<!doctype html><html lang="en">
 <head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
  <meta content="#3c790a" name="theme-color">
  <title>Streams Standard</title>
  <link crossorigin href="https://resources.whatwg.org/spec.css" rel="stylesheet">
  <link crossorigin href="https://resources.whatwg.org/standard.css" rel="stylesheet">
  <link crossorigin href="https://resources.whatwg.org/standard-shared-with-dev.css" rel="stylesheet">
  <link crossorigin href="https://resources.whatwg.org/logo-streams.svg" rel="icon">
<script async crossorigin src="https://resources.whatwg.org/file-issue.js"></script>
<script async crossorigin src="https://resources.whatwg.org/commit-snapshot-shortcut-key.js"></script>
<style>
  emu-val { font-weight: bold; }
  emu-alg > ol, emu-alg > ol ol ol ol { list-style-type: decimal; }
  emu-alg > ol ol, emu-alg > ol ol ol ol ol { list-style-type: lower-alpha; }
  emu-alg > ol ol ol, emu-alg > ol ol ol ol ol ol { list-style-type: lower-roman; }
  emu-alg li { margin: 0; }

  .heading .annotation {
    background-color: beige;
    border: 1px solid black;
    border-radius: 3px;
    cursor: help;
    display: inline-block;
    font-size: 70%;
    font-weight: normal;
    padding: 1px 2px;
  }
</style>
<style>/* style-dfn-panel */

.dfn-panel {
    position: absolute;
    z-index: 35;
    height: auto;
    width: -webkit-fit-content;
    width: fit-content;
    max-width: 300px;
    max-height: 500px;
    overflow: auto;
    padding: 0.5em 0.75em;
    font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
    background: #DDDDDD;
    color: black;
    border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
    display: inline-block;
    position: fixed;
    left: .5em;
    bottom: 2em;
    margin: 0 auto;
    max-width: calc(100vw - 1.5em - .4em - .5em);
    max-height: 30vh;
}

.dfn-paneled { cursor: pointer; }
</style>
 <body class="h-entry status-LS">
  <div class="head">
   <p data-fill-with="logo"><a class="logo" href="https://whatwg.org/"> <img alt="WHATWG" crossorigin height="100" src="https://resources.whatwg.org/logo-streams.svg"> </a> </p>
   <hgroup>
    <h1 class="p-name no-ref" id="title">Streams</h1>
    <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated <time class="dt-updated" datetime="1970-01-01">1 January 1970</time></span></h2>
   </hgroup>
   <div data-fill-with="spec-metadata">
    <dl>
     <dt>Participate:
     <dd><a href="https://github.com/whatwg/streams">GitHub whatwg/streams</a> (<a href="https://github.com/whatwg/streams/issues/new">new issue</a>, <a href="https://github.com/whatwg/streams/issues">open issues</a>)
     <dd><a href="https://wiki.whatwg.org/wiki/IRC">IRC: #whatwg on Freenode</a>
     <dt>Commits:
     <dd><a href="https://github.com/whatwg/streams/commits">GitHub whatwg/streams/commits</a>
     <dd>[SNAPSHOT-LINK]
     <dd><a href="https://twitter.com/streamsstandard">@streamsstandard</a>
     <dt>Tests:
     <dd><a href="https://github.com/web-platform-tests/wpt/tree/master/streams">web-platform-tests streams/</a> (<a href="https://github.com/web-platform-tests/wpt/labels/streams">ongoing work</a>)
     <dt>Translations <small>(non-normative)</small>:
     <dd><span title="Japanese"><a href="https://triple-underscore.github.io/Streams-ja.html" hreflang="ja" lang="ja" rel="alternate">日本語</a></span>
     <dt>Demos:
     <dd><a href="https://streams.spec.whatwg.org/demos/">streams.spec.whatwg.org/demos</a>
    </dl>
   </div>
   <div data-fill-with="warning"></div>
  </div>
  <div class="p-summary" data-fill-with="abstract">
   <h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
   <p>This specification provides APIs for creating, composing, and consuming streams of data that map efficiently

to low-level I/O primitives.</p>
  </div>
  <nav data-fill-with="table-of-contents" id="toc">
   <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
   <ol class="toc" role="directory">
    <li><a href="#intro"><span class="secno">1</span> <span class="content">Introduction</span></a>
    <li>
     <a href="#model"><span class="secno">2</span> <span class="content">Model</span></a>
     <ol class="toc">
      <li><a href="#rs-model"><span class="secno">2.1</span> <span class="content">Readable streams</span></a>
      <li><a href="#ws-model"><span class="secno">2.2</span> <span class="content">Writable streams</span></a>
      <li><a href="#ts-model"><span class="secno">2.3</span> <span class="content">Transform streams</span></a>
      <li><a href="#pipe-chains"><span class="secno">2.4</span> <span class="content">Pipe chains and backpressure</span></a>
      <li><a href="#queuing-strategies"><span class="secno">2.5</span> <span class="content">Internal queues and queuing strategies</span></a>
      <li><a href="#locking"><span class="secno">2.6</span> <span class="content">Locking</span></a>
     </ol>
    <li>
     <a href="#rs"><span class="secno">3</span> <span class="content">Readable streams</span></a>
     <ol class="toc">
      <li><a href="#rs-intro"><span class="secno">3.1</span> <span class="content">Using readable streams</span></a>
      <li>
       <a href="#rs-class"><span class="secno">3.2</span> <span class="content">Class <code>ReadableStream</code></span></a>
       <ol class="toc">
        <li><a href="#rs-class-definition"><span class="secno">3.2.1</span> <span class="content">Class definition</span></a>
        <li><a href="#rs-internal-slots"><span class="secno">3.2.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#rs-constructor"><span class="secno">3.2.3</span> <span class="content">new
ReadableStream(<var>underlyingSource</var> = {}, <var>strategy</var> = {})</span></a>
        <li><a href="#underlying-source-api"><span class="secno">3.2.4</span> <span class="content">Underlying source API</span></a>
        <li>
         <a href="#rs-prototype"><span class="secno">3.2.5</span> <span class="content">Properties of the <code class="idl"><span>ReadableStream</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#rs-locked"><span class="secno">3.2.5.1</span> <span class="content">get locked</span></a>
          <li><a href="#rs-cancel"><span class="secno">3.2.5.2</span> <span class="content">cancel(<var>reason</var>)</span></a>
          <li><a href="#rs-get-iterator"><span class="secno">3.2.5.3</span> <span class="content">getIterator({ <var>preventCancel</var> } = {})</span></a>
          <li><a href="#rs-get-reader"><span class="secno">3.2.5.4</span> <span class="content">getReader({ <var>mode</var> } = {})</span></a>
          <li><a href="#rs-pipe-through"><span class="secno">3.2.5.5</span> <span class="content">pipeThrough({ <var>writable</var>, <var>readable</var> }, { <var>preventClose</var>, <var>preventAbort</var>, <var>preventCancel</var>, <var>signal</var> } = {})</span></a>
          <li><a href="#rs-pipe-to"><span class="secno">3.2.5.6</span> <span class="content">pipeTo(<var>dest</var>,
{ <var>preventClose</var>, <var>preventAbort</var>, <var>preventCancel</var>, <var>signal</var> } = {})</span></a>
          <li><a href="#rs-tee"><span class="secno">3.2.5.7</span> <span class="content">tee()</span></a>
          <li><a href="#rs-asynciterator"><span class="secno">3.2.5.8</span> <span class="content">[@@asyncIterator]({ <var>preventCancel</var> } = {})</span></a>
         </ol>
       </ol>
      <li>
       <a href="#rs-asynciterator-prototype"><span class="secno">3.3</span> <span class="content">ReadableStreamAsyncIteratorPrototype</span></a>
       <ol class="toc">
        <li><a href="#default-reader-asynciterator-prototype-internal-slots"><span class="secno">3.3.1</span> <span class="content">Internal slots</span></a>
        <li><a href="#rs-asynciterator-prototype-next"><span class="secno">3.3.2</span> <span class="content">next()</span></a>
        <li><a href="#rs-asynciterator-prototype-return"><span class="secno">3.3.3</span> <span class="content">return( <var>value</var> )</span></a>
       </ol>
      <li>
       <a href="#rs-abstract-ops"><span class="secno">3.4</span> <span class="content">General readable stream abstract operations</span></a>
       <ol class="toc">
        <li><a href="#acquire-readable-stream-byob-reader"><span class="secno">3.4.1</span> <span class="content">AcquireReadableStreamBYOBReader ( <var>stream</var>[, <var>forAuthorCode</var> ] )</span></a>
        <li><a href="#acquire-readable-stream-reader"><span class="secno">3.4.2</span> <span class="content">AcquireReadableStreamDefaultReader ( <var>stream</var>[, <var>forAuthorCode</var> ] )</span></a>
        <li><a href="#create-readable-stream"><span class="secno">3.4.3</span> <span class="content">CreateReadableStream ( <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var> [, <var>highWaterMark</var> [, <var>sizeAlgorithm</var> ] ] )</span></a>
        <li><a href="#create-readable-byte-stream"><span class="secno">3.4.4</span> <span class="content">CreateReadableByteStream ( <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var> [, <var>highWaterMark</var> [, <var>autoAllocateChunkSize</var> ] ] )</span></a>
        <li><a href="#initialize-readable-stream"><span class="secno">3.4.5</span> <span class="content">InitializeReadableStream ( <var>stream</var> )</span></a>
        <li><a href="#is-readable-stream"><span class="secno">3.4.6</span> <span class="content">IsReadableStream ( <var>x</var> )</span></a>
        <li><a href="#is-readable-stream-disturbed"><span class="secno">3.4.7</span> <span class="content">IsReadableStreamDisturbed ( <var>stream</var> )</span></a>
        <li><a href="#is-readable-stream-locked"><span class="secno">3.4.8</span> <span class="content">IsReadableStreamLocked ( <var>stream</var> )</span></a>
        <li><a href="#is-readable-stream-asynciterator"><span class="secno">3.4.9</span> <span class="content">IsReadableStreamAsyncIterator ( <var>x</var> )</span></a>
        <li><a href="#readable-stream-tee"><span class="secno">3.4.10</span> <span class="content">ReadableStreamTee ( <var>stream</var>, <var>cloneForBranch2</var> )</span></a>
        <li><a href="#readable-stream-pipe-to"><span class="secno">3.4.11</span> <span class="content">ReadableStreamPipeTo ( <var>source</var>, <var>dest</var>, <var>preventClose</var>, <var>preventAbort</var>, <var>preventCancel</var>, <var>signal</var> )</span></a>
       </ol>
      <li>
       <a href="#rs-abstract-ops-used-by-controllers"><span class="secno">3.5</span> <span class="content">The interface between readable streams and controllers</span></a>
       <ol class="toc">
        <li><a href="#readable-stream-add-read-into-request"><span class="secno">3.5.1</span> <span class="content">ReadableStreamAddReadIntoRequest ( <var>stream</var> )</span></a>
        <li><a href="#readable-stream-add-read-request"><span class="secno">3.5.2</span> <span class="content">ReadableStreamAddReadRequest ( <var>stream</var> )</span></a>
        <li><a href="#readable-stream-cancel"><span class="secno">3.5.3</span> <span class="content">ReadableStreamCancel ( <var>stream</var>, <var>reason</var> )</span></a>
        <li><a href="#readable-stream-close"><span class="secno">3.5.4</span> <span class="content">ReadableStreamClose ( <var>stream</var> )</span></a>
        <li><a href="#readable-stream-create-read-result"><span class="secno">3.5.5</span> <span class="content">ReadableStreamCreateReadResult
( <var>value</var>, <var>done</var>, <var>forAuthorCode</var> )</span></a>
        <li><a href="#readable-stream-error"><span class="secno">3.5.6</span> <span class="content">ReadableStreamError ( <var>stream</var>, <var>e</var> )</span></a>
        <li><a href="#readable-stream-fulfill-read-into-request"><span class="secno">3.5.7</span> <span class="content">ReadableStreamFulfillReadIntoRequest ( <var>stream</var>, <var>chunk</var>, <var>done</var> )</span></a>
        <li><a href="#readable-stream-fulfill-read-request"><span class="secno">3.5.8</span> <span class="content">ReadableStreamFulfillReadRequest ( <var>stream</var>, <var>chunk</var>, <var>done</var> )</span></a>
        <li><a href="#readable-stream-get-num-read-into-requests"><span class="secno">3.5.9</span> <span class="content">ReadableStreamGetNumReadIntoRequests ( <var>stream</var> )</span></a>
        <li><a href="#readable-stream-get-num-read-requests"><span class="secno">3.5.10</span> <span class="content">ReadableStreamGetNumReadRequests ( <var>stream</var> )</span></a>
        <li><a href="#readable-stream-has-byob-reader"><span class="secno">3.5.11</span> <span class="content">ReadableStreamHasBYOBReader ( <var>stream</var> )</span></a>
        <li><a href="#readable-stream-has-default-reader"><span class="secno">3.5.12</span> <span class="content">ReadableStreamHasDefaultReader ( <var>stream</var> )</span></a>
       </ol>
      <li>
       <a href="#default-reader-class"><span class="secno">3.6</span> <span class="content">Class <code>ReadableStreamDefaultReader</code></span></a>
       <ol class="toc">
        <li><a href="#default-reader-class-definition"><span class="secno">3.6.1</span> <span class="content">Class definition</span></a>
        <li><a href="#default-reader-internal-slots"><span class="secno">3.6.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#default-reader-constructor"><span class="secno">3.6.3</span> <span class="content">new ReadableStreamDefaultReader(<var>stream</var>)</span></a>
        <li>
         <a href="#default-reader-prototype"><span class="secno">3.6.4</span> <span class="content">Properties of the <code class="idl"><span>ReadableStreamDefaultReader</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#default-reader-closed"><span class="secno">3.6.4.1</span> <span class="content">get closed</span></a>
          <li><a href="#default-reader-cancel"><span class="secno">3.6.4.2</span> <span class="content">cancel(<var>reason</var>)</span></a>
          <li><a href="#default-reader-read"><span class="secno">3.6.4.3</span> <span class="content">read()</span></a>
          <li><a href="#default-reader-release-lock"><span class="secno">3.6.4.4</span> <span class="content">releaseLock()</span></a>
         </ol>
       </ol>
      <li>
       <a href="#byob-reader-class"><span class="secno">3.7</span> <span class="content">Class <code>ReadableStreamBYOBReader</code></span></a>
       <ol class="toc">
        <li><a href="#byob-reader-class-definition"><span class="secno">3.7.1</span> <span class="content">Class definition</span></a>
        <li><a href="#byob-reader-internal-slots"><span class="secno">3.7.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#byob-reader-constructor"><span class="secno">3.7.3</span> <span class="content">new
ReadableStreamBYOBReader(<var>stream</var>)</span></a>
        <li>
         <a href="#byob-reader-prototype"><span class="secno">3.7.4</span> <span class="content">Properties of the <code class="idl"><span>ReadableStreamBYOBReader</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#byob-reader-closed"><span class="secno">3.7.4.1</span> <span class="content">get closed</span></a>
          <li><a href="#byob-reader-cancel"><span class="secno">3.7.4.2</span> <span class="content">cancel(<var>reason</var>)</span></a>
          <li><a href="#byob-reader-read"><span class="secno">3.7.4.3</span> <span class="content">read(<var>view</var>)</span></a>
          <li><a href="#byob-reader-release-lock"><span class="secno">3.7.4.4</span> <span class="content">releaseLock()</span></a>
         </ol>
       </ol>
      <li>
       <a href="#rs-reader-abstract-ops"><span class="secno">3.8</span> <span class="content">Readable stream reader abstract operations</span></a>
       <ol class="toc">
        <li><a href="#is-readable-stream-default-reader"><span class="secno">3.8.1</span> <span class="content">IsReadableStreamDefaultReader ( <var>x</var> )</span></a>
        <li><a href="#is-readable-stream-byob-reader"><span class="secno">3.8.2</span> <span class="content">IsReadableStreamBYOBReader ( <var>x</var> )</span></a>
        <li><a href="#readable-stream-reader-generic-cancel"><span class="secno">3.8.3</span> <span class="content">ReadableStreamReaderGenericCancel ( <var>reader</var>, <var>reason</var> )</span></a>
        <li><a href="#readable-stream-reader-generic-initialize"><span class="secno">3.8.4</span> <span class="content">ReadableStreamReaderGenericInitialize ( <var>reader</var>, <var>stream</var> )</span></a>
        <li><a href="#readable-stream-reader-generic-release"><span class="secno">3.8.5</span> <span class="content">ReadableStreamReaderGenericRelease ( <var>reader</var> )</span></a>
        <li><a href="#readable-stream-byob-reader-read"><span class="secno">3.8.6</span> <span class="content">ReadableStreamBYOBReaderRead
( <var>reader</var>, <var>view</var> )</span></a>
        <li><a href="#readable-stream-default-reader-read"><span class="secno">3.8.7</span> <span class="content">ReadableStreamDefaultReaderRead ( <var>reader</var> )</span></a>
       </ol>
      <li>
       <a href="#rs-default-controller-class"><span class="secno">3.9</span> <span class="content">Class <code>ReadableStreamDefaultController</code></span></a>
       <ol class="toc">
        <li><a href="#rs-default-controller-class-definition"><span class="secno">3.9.1</span> <span class="content">Class definition</span></a>
        <li><a href="#rs-default-controller-internal-slots"><span class="secno">3.9.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#rs-default-controller-constructor"><span class="secno">3.9.3</span> <span class="content">new ReadableStreamDefaultController()</span></a>
        <li>
         <a href="#rs-default-controller-prototype"><span class="secno">3.9.4</span> <span class="content">Properties of the <code class="idl"><span>ReadableStreamDefaultController</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#rs-default-controller-desired-size"><span class="secno">3.9.4.1</span> <span class="content">get
desiredSize</span></a>
          <li><a href="#rs-default-controller-close"><span class="secno">3.9.4.2</span> <span class="content">close()</span></a>
          <li><a href="#rs-default-controller-enqueue"><span class="secno">3.9.4.3</span> <span class="content">enqueue(<var>chunk</var>)</span></a>
          <li><a href="#rs-default-controller-error"><span class="secno">3.9.4.4</span> <span class="content">error(<var>e</var>)</span></a>
         </ol>
        <li>
         <a href="#rs-default-controller-internal-methods"><span class="secno">3.9.5</span> <span class="content">Readable stream default controller internal methods</span></a>
         <ol class="toc">
          <li><a href="#rs-default-controller-private-cancel"><span class="secno">3.9.5.1</span> <span class="content"><span>[[CancelSteps]]</span>(<var>reason</var>)</span></a>
          <li><a href="#rs-default-controller-private-pull"><span class="secno">3.9.5.2</span> <span class="content"><span>[[PullSteps]]</span>( )</span></a>
         </ol>
       </ol>
      <li>
       <a href="#rs-default-controller-abstract-ops"><span class="secno">3.10</span> <span class="content">Readable stream default controller abstract operations</span></a>
       <ol class="toc">
        <li><a href="#is-readable-stream-default-controller"><span class="secno">3.10.1</span> <span class="content">IsReadableStreamDefaultController ( <var>x</var> )</span></a>
        <li><a href="#readable-stream-default-controller-call-pull-if-needed"><span class="secno">3.10.2</span> <span class="content">ReadableStreamDefaultControllerCallPullIfNeeded ( <var>controller</var> )</span></a>
        <li><a href="#readable-stream-default-controller-should-call-pull"><span class="secno">3.10.3</span> <span class="content">ReadableStreamDefaultControllerShouldCallPull ( <var>controller</var> )</span></a>
        <li><a href="#readable-stream-default-controller-clear-algorithms"><span class="secno">3.10.4</span> <span class="content">ReadableStreamDefaultControllerClearAlgorithms ( <var>controller</var> )</span></a>
        <li><a href="#readable-stream-default-controller-close"><span class="secno">3.10.5</span> <span class="content">ReadableStreamDefaultControllerClose ( <var>controller</var> )</span></a>
        <li><a href="#readable-stream-default-controller-enqueue"><span class="secno">3.10.6</span> <span class="content">ReadableStreamDefaultControllerEnqueue ( <var>controller</var>, <var>chunk</var> )</span></a>
        <li><a href="#readable-stream-default-controller-error"><span class="secno">3.10.7</span> <span class="content">ReadableStreamDefaultControllerError ( <var>controller</var>, <var>e</var> )</span></a>
        <li><a href="#readable-stream-default-controller-get-desired-size"><span class="secno">3.10.8</span> <span class="content">ReadableStreamDefaultControllerGetDesiredSize ( <var>controller</var> )</span></a>
        <li><a href="#rs-default-controller-has-backpressure"><span class="secno">3.10.9</span> <span class="content">ReadableStreamDefaultControllerHasBackpressure ( <var>controller</var> )</span></a>
        <li><a href="#readable-stream-default-controller-can-close-or-enqueue"><span class="secno">3.10.10</span> <span class="content">ReadableStreamDefaultControllerCanCloseOrEnqueue ( <var>controller</var> )</span></a>
        <li><a href="#set-up-readable-stream-default-controller"><span class="secno">3.10.11</span> <span class="content">SetUpReadableStreamDefaultController(<var>stream</var>, <var>controller</var>, <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span></a>
        <li><a href="#set-up-readable-stream-default-controller-from-underlying-source"><span class="secno">3.10.12</span> <span class="content">SetUpReadableStreamDefaultControllerFromUnderlyingSource(<var>stream</var>, <var>underlyingSource</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span></a>
       </ol>
      <li>
       <a href="#rbs-controller-class"><span class="secno">3.11</span> <span class="content">Class <code>ReadableByteStreamController</code></span></a>
       <ol class="toc">
        <li><a href="#rbs-controller-class-definition"><span class="secno">3.11.1</span> <span class="content">Class definition</span></a>
        <li><a href="#rbs-controller-internal-slots"><span class="secno">3.11.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#rbs-controller-constructor"><span class="secno">3.11.3</span> <span class="content">new
ReadableByteStreamController()</span></a>
        <li>
         <a href="#rbs-controller-prototype"><span class="secno">3.11.4</span> <span class="content">Properties of the <code class="idl"><span>ReadableByteStreamController</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#rbs-controller-byob-request"><span class="secno">3.11.4.1</span> <span class="content">get byobRequest</span></a>
          <li><a href="#rbs-controller-desired-size"><span class="secno">3.11.4.2</span> <span class="content">get desiredSize</span></a>
          <li><a href="#rbs-controller-close"><span class="secno">3.11.4.3</span> <span class="content">close()</span></a>
          <li><a href="#rbs-controller-enqueue"><span class="secno">3.11.4.4</span> <span class="content">enqueue(<var>chunk</var>)</span></a>
          <li><a href="#rbs-controller-error"><span class="secno">3.11.4.5</span> <span class="content">error(<var>e</var>)</span></a>
         </ol>
        <li>
         <a href="#rbs-controller-internal-methods"><span class="secno">3.11.5</span> <span class="content">Readable stream BYOB controller internal methods</span></a>
         <ol class="toc">
          <li><a href="#rbs-controller-private-cancel"><span class="secno">3.11.5.1</span> <span class="content"><span>[[CancelSteps]]</span>(<var>reason</var>)</span></a>
          <li><a href="#rbs-controller-private-pull"><span class="secno">3.11.5.2</span> <span class="content"><span>[[PullSteps]]</span>( )</span></a>
         </ol>
       </ol>
      <li>
       <a href="#rs-byob-request-class"><span class="secno">3.12</span> <span class="content">Class <code>ReadableStreamBYOBRequest</code></span></a>
       <ol class="toc">
        <li><a href="#rs-byob-request-class-definition"><span class="secno">3.12.1</span> <span class="content">Class definition</span></a>
        <li><a href="#rs-byob-request-internal-slots"><span class="secno">3.12.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#rs-byob-request-constructor"><span class="secno">3.12.3</span> <span class="content">new
ReadableStreamBYOBRequest()</span></a>
        <li>
         <a href="#rs-byob-request-prototype"><span class="secno">3.12.4</span> <span class="content">Properties of the <code class="idl"><span>ReadableStreamBYOBRequest</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#rs-byob-request-view"><span class="secno">3.12.4.1</span> <span class="content">get view</span></a>
          <li><a href="#rs-byob-request-respond"><span class="secno">3.12.4.2</span> <span class="content">respond(<var>bytesWritten</var>)</span></a>
          <li><a href="#rs-byob-request-respond-with-new-view"><span class="secno">3.12.4.3</span> <span class="content">respondWithNewView(<var>view</var>)</span></a>
         </ol>
       </ol>
      <li>
       <a href="#rbs-controller-abstract-ops"><span class="secno">3.13</span> <span class="content">Readable stream BYOB controller abstract operations</span></a>
       <ol class="toc">
        <li><a href="#is-readable-stream-byob-request"><span class="secno">3.13.1</span> <span class="content">IsReadableStreamBYOBRequest ( <var>x</var> )</span></a>
        <li><a href="#is-readable-byte-stream-controller"><span class="secno">3.13.2</span> <span class="content">IsReadableByteStreamController
( <var>x</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-call-pull-if-needed"><span class="secno">3.13.3</span> <span class="content">ReadableByteStreamControllerCallPullIfNeeded ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-clear-algorithms"><span class="secno">3.13.4</span> <span class="content">ReadableByteStreamControllerClearAlgorithms ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-clear-pending-pull-intos"><span class="secno">3.13.5</span> <span class="content">ReadableByteStreamControllerClearPendingPullIntos ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-close"><span class="secno">3.13.6</span> <span class="content">ReadableByteStreamControllerClose ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-commit-pull-into-descriptor"><span class="secno">3.13.7</span> <span class="content">ReadableByteStreamControllerCommitPullIntoDescriptor
( <var>stream</var>, <var>pullIntoDescriptor</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-convert-pull-into-descriptor"><span class="secno">3.13.8</span> <span class="content">ReadableByteStreamControllerConvertPullIntoDescriptor ( <var>pullIntoDescriptor</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-enqueue"><span class="secno">3.13.9</span> <span class="content">ReadableByteStreamControllerEnqueue ( <var>controller</var>, <var>chunk</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-enqueue-chunk-to-queue"><span class="secno">3.13.10</span> <span class="content">ReadableByteStreamControllerEnqueueChunkToQueue ( <var>controller</var>, <var>buffer</var>, <var>byteOffset</var>, <var>byteLength</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-error"><span class="secno">3.13.11</span> <span class="content">ReadableByteStreamControllerError ( <var>controller</var>, <var>e</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-fill-head-pull-into-descriptor"><span class="secno">3.13.12</span> <span class="content">ReadableByteStreamControllerFillHeadPullIntoDescriptor ( <var>controller</var>, <var>size</var>, <var>pullIntoDescriptor</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-fill-pull-into-descriptor-from-queue"><span class="secno">3.13.13</span> <span class="content">ReadableByteStreamControllerFillPullIntoDescriptorFromQueue ( <var>controller</var>, <var>pullIntoDescriptor</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-get-desired-size"><span class="secno">3.13.14</span> <span class="content">ReadableByteStreamControllerGetDesiredSize ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-handle-queue-drain"><span class="secno">3.13.15</span> <span class="content">ReadableByteStreamControllerHandleQueueDrain ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-invalidate-byob-request"><span class="secno">3.13.16</span> <span class="content">ReadableByteStreamControllerInvalidateBYOBRequest ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-process-pull-into-descriptors-using-queue"><span class="secno">3.13.17</span> <span class="content">ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-pull-into"><span class="secno">3.13.18</span> <span class="content">ReadableByteStreamControllerPullInto ( <var>controller</var>, <var>view</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-respond"><span class="secno">3.13.19</span> <span class="content">ReadableByteStreamControllerRespond ( <var>controller</var>, <var>bytesWritten</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-respond-in-closed-state"><span class="secno">3.13.20</span> <span class="content">ReadableByteStreamControllerRespondInClosedState ( <var>controller</var>, <var>firstDescriptor</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-respond-in-readable-state"><span class="secno">3.13.21</span> <span class="content">ReadableByteStreamControllerRespondInReadableState ( <var>controller</var>, <var>bytesWritten</var>, <var>pullIntoDescriptor</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-respond-internal"><span class="secno">3.13.22</span> <span class="content">ReadableByteStreamControllerRespondInternal ( <var>controller</var>, <var>bytesWritten</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-respond-with-new-view"><span class="secno">3.13.23</span> <span class="content">ReadableByteStreamControllerRespondWithNewView ( <var>controller</var>, <var>view</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-shift-pending-pull-into"><span class="secno">3.13.24</span> <span class="content">ReadableByteStreamControllerShiftPendingPullInto ( <var>controller</var> )</span></a>
        <li><a href="#readable-byte-stream-controller-should-call-pull"><span class="secno">3.13.25</span> <span class="content">ReadableByteStreamControllerShouldCallPull ( <var>controller</var> )</span></a>
        <li><a href="#set-up-readable-byte-stream-controller"><span class="secno">3.13.26</span> <span class="content">SetUpReadableByteStreamController ( <var>stream</var>, <var>controller</var>, <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var>, <var>highWaterMark</var>, <var>autoAllocateChunkSize</var> )</span></a>
        <li><a href="#set-up-readable-byte-stream-controller-from-underlying-source"><span class="secno">3.13.27</span> <span class="content">SetUpReadableByteStreamControllerFromUnderlyingSource ( <var>stream</var>, <var>underlyingByteSource</var>, <var>highWaterMark</var> )</span></a>
        <li><a href="#set-up-readable-stream-byob-request"><span class="secno">3.13.28</span> <span class="content">SetUpReadableStreamBYOBRequest ( <var>request</var>, <var>controller</var>, <var>view</var> )</span></a>
       </ol>
     </ol>
    <li>
     <a href="#ws"><span class="secno">4</span> <span class="content">Writable streams</span></a>
     <ol class="toc">
      <li><a href="#ws-intro"><span class="secno">4.1</span> <span class="content">Using writable streams</span></a>
      <li>
       <a href="#ws-class"><span class="secno">4.2</span> <span class="content">Class <code>WritableStream</code></span></a>
       <ol class="toc">
        <li><a href="#ws-class-definition"><span class="secno">4.2.1</span> <span class="content">Class definition</span></a>
        <li><a href="#ws-internal-slots"><span class="secno">4.2.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#ws-constructor"><span class="secno">4.2.3</span> <span class="content">new
WritableStream(<var>underlyingSink</var> = {}, <var>strategy</var> = {})</span></a>
        <li><a href="#underlying-sink-api"><span class="secno">4.2.4</span> <span class="content">Underlying sink API</span></a>
        <li>
         <a href="#ws-prototype"><span class="secno">4.2.5</span> <span class="content">Properties of the <code class="idl"><span>WritableStream</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#ws-locked"><span class="secno">4.2.5.1</span> <span class="content">get locked</span></a>
          <li><a href="#ws-abort"><span class="secno">4.2.5.2</span> <span class="content">abort(<var>reason</var>)</span></a>
          <li><a href="#ws-close"><span class="secno">4.2.5.3</span> <span class="content">close()</span></a>
          <li><a href="#ws-get-writer"><span class="secno">4.2.5.4</span> <span class="content">getWriter()</span></a>
         </ol>
       </ol>
      <li>
       <a href="#ws-abstract-ops"><span class="secno">4.3</span> <span class="content">General writable stream abstract operations</span></a>
       <ol class="toc">
        <li><a href="#acquire-writable-stream-default-writer"><span class="secno">4.3.1</span> <span class="content">AcquireWritableStreamDefaultWriter ( <var>stream</var> )</span></a>
        <li><a href="#create-writable-stream"><span class="secno">4.3.2</span> <span class="content">CreateWritableStream ( <var>startAlgorithm</var>, <var>writeAlgorithm</var>, <var>closeAlgorithm</var>, <var>abortAlgorithm</var> [, <var>highWaterMark</var> [, <var>sizeAlgorithm</var> ] ] )</span></a>
        <li><a href="#initialize-writable-stream"><span class="secno">4.3.3</span> <span class="content">InitializeWritableStream ( <var>stream</var> )</span></a>
        <li><a href="#is-writable-stream"><span class="secno">4.3.4</span> <span class="content">IsWritableStream ( <var>x</var> )</span></a>
        <li><a href="#is-writable-stream-locked"><span class="secno">4.3.5</span> <span class="content">IsWritableStreamLocked ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-abort"><span class="secno">4.3.6</span> <span class="content">WritableStreamAbort ( <var>stream</var>, <var>reason</var> )</span></a>
        <li><a href="#writable-stream-close"><span class="secno">4.3.7</span> <span class="content">WritableStreamClose ( <var>stream</var> )</span></a>
       </ol>
      <li>
       <a href="#ws-abstract-ops-used-by-controllers"><span class="secno">4.4</span> <span class="content">Writable stream abstract operations used by controllers</span></a>
       <ol class="toc">
        <li><a href="#writable-stream-add-write-request"><span class="secno">4.4.1</span> <span class="content">WritableStreamAddWriteRequest ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-deal-with-rejection"><span class="secno">4.4.2</span> <span class="content">WritableStreamDealWithRejection ( <var>stream</var>, <var>error</var> )</span></a>
        <li><a href="#writable-stream-start-erroring"><span class="secno">4.4.3</span> <span class="content">WritableStreamStartErroring ( <var>stream</var>, <var>reason</var> )</span></a>
        <li><a href="#writable-stream-finish-erroring"><span class="secno">4.4.4</span> <span class="content">WritableStreamFinishErroring
( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-finish-in-flight-write"><span class="secno">4.4.5</span> <span class="content">WritableStreamFinishInFlightWrite ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-finish-in-flight-write-with-error"><span class="secno">4.4.6</span> <span class="content">WritableStreamFinishInFlightWriteWithError ( <var>stream</var>, <var>error</var> )</span></a>
        <li><a href="#writable-stream-finish-in-flight-close"><span class="secno">4.4.7</span> <span class="content">WritableStreamFinishInFlightClose ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-finish-in-flight-close-with-error"><span class="secno">4.4.8</span> <span class="content">WritableStreamFinishInFlightCloseWithError ( <var>stream</var>, <var>error</var> )</span></a>
        <li><a href="#writable-stream-close-queued-or-in-flight"><span class="secno">4.4.9</span> <span class="content"> WritableStreamCloseQueuedOrInFlight ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-has-operation-marked-in-flight"><span class="secno">4.4.10</span> <span class="content">WritableStreamHasOperationMarkedInFlight ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-mark-close-request-in-flight"><span class="secno">4.4.11</span> <span class="content">WritableStreamMarkCloseRequestInFlight ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-mark-first-write-request-in-flight"><span class="secno">4.4.12</span> <span class="content">WritableStreamMarkFirstWriteRequestInFlight ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-reject-close-and-closed-promise-if-needed"><span class="secno">4.4.13</span> <span class="content">WritableStreamRejectCloseAndClosedPromiseIfNeeded ( <var>stream</var> )</span></a>
        <li><a href="#writable-stream-update-backpressure"><span class="secno">4.4.14</span> <span class="content">WritableStreamUpdateBackpressure ( <var>stream</var>, <var>backpressure</var> )</span></a>
       </ol>
      <li>
       <a href="#default-writer-class"><span class="secno">4.5</span> <span class="content">Class <code>WritableStreamDefaultWriter</code></span></a>
       <ol class="toc">
        <li><a href="#default-writer-class-definition"><span class="secno">4.5.1</span> <span class="content">Class definition</span></a>
        <li><a href="#default-writer-internal-slots"><span class="secno">4.5.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#default-writer-constructor"><span class="secno">4.5.3</span> <span class="content">new WritableStreamDefaultWriter(<var>stream</var>)</span></a>
        <li>
         <a href="#default-writer-prototype"><span class="secno">4.5.4</span> <span class="content">Properties of the <code class="idl"><span>WritableStreamDefaultWriter</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#default-writer-closed"><span class="secno">4.5.4.1</span> <span class="content">get closed</span></a>
          <li><a href="#default-writer-desired-size"><span class="secno">4.5.4.2</span> <span class="content">get desiredSize</span></a>
          <li><a href="#default-writer-ready"><span class="secno">4.5.4.3</span> <span class="content">get ready</span></a>
          <li><a href="#default-writer-abort"><span class="secno">4.5.4.4</span> <span class="content">abort(<var>reason</var>)</span></a>
          <li><a href="#default-writer-close"><span class="secno">4.5.4.5</span> <span class="content">close()</span></a>
          <li><a href="#default-writer-release-lock"><span class="secno">4.5.4.6</span> <span class="content">releaseLock()</span></a>
          <li><a href="#default-writer-write"><span class="secno">4.5.4.7</span> <span class="content">write(<var>chunk</var>)</span></a>
         </ol>
       </ol>
      <li>
       <a href="#rs-writer-abstract-ops"><span class="secno">4.6</span> <span class="content">Writable stream writer abstract operations</span></a>
       <ol class="toc">
        <li><a href="#is-writable-stream-default-writer"><span class="secno">4.6.1</span> <span class="content">IsWritableStreamDefaultWriter ( <var>x</var> )</span></a>
        <li><a href="#writable-stream-default-writer-abort"><span class="secno">4.6.2</span> <span class="content">WritableStreamDefaultWriterAbort ( <var>writer</var>, <var>reason</var> )</span></a>
        <li><a href="#writable-stream-default-writer-close"><span class="secno">4.6.3</span> <span class="content">WritableStreamDefaultWriterClose ( <var>writer</var> )</span></a>
        <li><a href="#writable-stream-default-writer-close-with-error-propagation"><span class="secno">4.6.4</span> <span class="content">WritableStreamDefaultWriterCloseWithErrorPropagation ( <var>writer</var> )</span></a>
        <li><a href="#writable-stream-default-writer-ensure-closed-promise-rejected"><span class="secno">4.6.5</span> <span class="content">WritableStreamDefaultWriterEnsureClosedPromiseRejected( <var>writer</var>, <var>error</var> )</span></a>
        <li><a href="#writable-stream-default-writer-ensure-ready-promise-rejected"><span class="secno">4.6.6</span> <span class="content">WritableStreamDefaultWriterEnsureReadyPromiseRejected( <var>writer</var>, <var>error</var> )</span></a>
        <li><a href="#writable-stream-default-writer-get-desired-size"><span class="secno">4.6.7</span> <span class="content">WritableStreamDefaultWriterGetDesiredSize ( <var>writer</var> )</span></a>
        <li><a href="#writable-stream-default-writer-release"><span class="secno">4.6.8</span> <span class="content">WritableStreamDefaultWriterRelease ( <var>writer</var> )</span></a>
        <li><a href="#writable-stream-default-writer-write"><span class="secno">4.6.9</span> <span class="content">WritableStreamDefaultWriterWrite ( <var>writer</var>, <var>chunk</var> )</span></a>
       </ol>
      <li>
       <a href="#ws-default-controller-class"><span class="secno">4.7</span> <span class="content">Class <code>WritableStreamDefaultController</code></span></a>
       <ol class="toc">
        <li><a href="#ws-default-controller-class-definition"><span class="secno">4.7.1</span> <span class="content">Class definition</span></a>
        <li><a href="#ws-default-controller-internal-slots"><span class="secno">4.7.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#ws-default-controller-constructor"><span class="secno">4.7.3</span> <span class="content">new WritableStreamDefaultController()</span></a>
        <li>
         <a href="#ws-default-controller-prototype"><span class="secno">4.7.4</span> <span class="content">Properties of the <code class="idl"><span>WritableStreamDefaultController</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#ws-default-controller-error"><span class="secno">4.7.4.1</span> <span class="content">error(<var>e</var>)</span></a>
         </ol>
        <li>
         <a href="#ws-default-controller-internal-methods"><span class="secno">4.7.5</span> <span class="content">Writable stream default controller internal methods</span></a>
         <ol class="toc">
          <li><a href="#ws-default-controller-private-abort"><span class="secno">4.7.5.1</span> <span class="content">[[AbortSteps]]( <var>reason</var> )</span></a>
          <li><a href="#ws-default-controller-private-error"><span class="secno">4.7.5.2</span> <span class="content">[[ErrorSteps]]()</span></a>
         </ol>
       </ol>
      <li>
       <a href="#ws-default-controller-abstract-ops"><span class="secno">4.8</span> <span class="content">Writable stream default controller abstract operations</span></a>
       <ol class="toc">
        <li><a href="#is-writable-stream-default-controller"><span class="secno">4.8.1</span> <span class="content">IsWritableStreamDefaultController ( <var>x</var> )</span></a>
        <li><a href="#set-up-writable-stream-default-controller"><span class="secno">4.8.2</span> <span class="content">SetUpWritableStreamDefaultController ( <var>stream</var>, <var>controller</var>, <var>startAlgorithm</var>, <var>writeAlgorithm</var>, <var>closeAlgorithm</var>, <var>abortAlgorithm</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span></a>
        <li><a href="#set-up-writable-stream-default-controller-from-underlying-sink"><span class="secno">4.8.3</span> <span class="content">SetUpWritableStreamDefaultControllerFromUnderlyingSink ( <var>stream</var>, <var>underlyingSink</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span></a>
        <li><a href="#writable-stream-default-controller-clear-algorithms"><span class="secno">4.8.4</span> <span class="content">WritableStreamDefaultControllerClearAlgorithms ( <var>controller</var> )</span></a>
        <li><a href="#writable-stream-default-controller-close"><span class="secno">4.8.5</span> <span class="content">WritableStreamDefaultControllerClose ( <var>controller</var> )</span></a>
        <li><a href="#writable-stream-default-controller-get-chunk-size"><span class="secno">4.8.6</span> <span class="content">WritableStreamDefaultControllerGetChunkSize ( <var>controller</var>, <var>chunk</var> )</span></a>
        <li><a href="#writable-stream-default-controller-get-desired-size"><span class="secno">4.8.7</span> <span class="content">WritableStreamDefaultControllerGetDesiredSize ( <var>controller</var> )</span></a>
        <li><a href="#writable-stream-default-controller-write"><span class="secno">4.8.8</span> <span class="content">WritableStreamDefaultControllerWrite ( <var>controller</var>, <var>chunk</var>, <var>chunkSize</var> )</span></a>
        <li><a href="#writable-stream-default-controller-advance-queue-if-needed"><span class="secno">4.8.9</span> <span class="content">WritableStreamDefaultControllerAdvanceQueueIfNeeded ( <var>controller</var> )</span></a>
        <li><a href="#writable-stream-default-controller-error-if-needed"><span class="secno">4.8.10</span> <span class="content">WritableStreamDefaultControllerErrorIfNeeded ( <var>controller</var>, <var>error</var> )</span></a>
        <li><a href="#writable-stream-default-controller-process-close"><span class="secno">4.8.11</span> <span class="content">WritableStreamDefaultControllerProcessClose ( <var>controller</var> )</span></a>
        <li><a href="#writable-stream-default-controller-process-write"><span class="secno">4.8.12</span> <span class="content">WritableStreamDefaultControllerProcessWrite ( <var>controller</var>, <var>chunk</var> )</span></a>
        <li><a href="#writable-stream-default-controller-get-backpressure"><span class="secno">4.8.13</span> <span class="content">WritableStreamDefaultControllerGetBackpressure ( <var>controller</var> )</span></a>
        <li><a href="#writable-stream-default-controller-error"><span class="secno">4.8.14</span> <span class="content">WritableStreamDefaultControllerError ( <var>controller</var>, <var>error</var> )</span></a>
       </ol>
     </ol>
    <li>
     <a href="#ts"><span class="secno">5</span> <span class="content">Transform streams</span></a>
     <ol class="toc">
      <li><a href="#ts-intro"><span class="secno">5.1</span> <span class="content">Using transform streams</span></a>
      <li>
       <a href="#ts-class"><span class="secno">5.2</span> <span class="content">Class <code>TransformStream</code></span></a>
       <ol class="toc">
        <li><a href="#ts-class-definition"><span class="secno">5.2.1</span> <span class="content">Class definition</span></a>
        <li><a href="#ts-internal-slots"><span class="secno">5.2.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#ts-constructor"><span class="secno">5.2.3</span> <span class="content">new TransformStream(<var>transformer</var> = {}, <var>writableStrategy</var> = {}, <var>readableStrategy</var> = {})</span></a>
        <li><a href="#transformer-api"><span class="secno">5.2.4</span> <span class="content">Transformer API</span></a>
        <li>
         <a href="#ts-prototype"><span class="secno">5.2.5</span> <span class="content">Properties of the <code class="idl"><span>TransformStream</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#ts-readable"><span class="secno">5.2.5.1</span> <span class="content">get readable</span></a>
          <li><a href="#ts-writable"><span class="secno">5.2.5.2</span> <span class="content">get writable</span></a>
         </ol>
       </ol>
      <li>
       <a href="#ts-abstract-ops"><span class="secno">5.3</span> <span class="content">General transform stream abstract operations</span></a>
       <ol class="toc">
        <li><a href="#create-transform-stream"><span class="secno">5.3.1</span> <span class="content">CreateTransformStream ( <var>startAlgorithm</var>, <var>transformAlgorithm</var>, <var>flushAlgorithm</var> [, <var>writableHighWaterMark</var> [, <var>writableSizeAlgorithm</var> [, <var>readableHighWaterMark</var> [, <var>readableSizeAlgorithm</var> ] ] ] ] )</span></a>
        <li><a href="#initialize-transform-stream"><span class="secno">5.3.2</span> <span class="content">InitializeTransformStream ( <var>stream</var>, <var>startPromise</var>, <var>writableHighWaterMark</var>, <var>writableSizeAlgorithm</var>, <var>readableHighWaterMark</var>, <var>readableSizeAlgorithm</var> )</span></a>
        <li><a href="#is-transform-stream"><span class="secno">5.3.3</span> <span class="content">IsTransformStream ( <var>x</var> )</span></a>
        <li><a href="#transform-stream-error"><span class="secno">5.3.4</span> <span class="content">TransformStreamError ( <var>stream</var>, <var>e</var> )</span></a>
        <li><a href="#transform-stream-error-writable-and-unblock-write"><span class="secno">5.3.5</span> <span class="content">TransformStreamErrorWritableAndUnblockWrite ( <var>stream</var>, <var>e</var> )</span></a>
        <li><a href="#transform-stream-set-backpressure"><span class="secno">5.3.6</span> <span class="content">TransformStreamSetBackpressure
( <var>stream</var>, <var>backpressure</var> )</span></a>
       </ol>
      <li>
       <a href="#ts-default-controller-class"><span class="secno">5.4</span> <span class="content">Class <code>TransformStreamDefaultController</code></span></a>
       <ol class="toc">
        <li><a href="#ts-default-controller-class-definition"><span class="secno">5.4.1</span> <span class="content">Class definition</span></a>
        <li><a href="#ts-default-controller-internal-slots"><span class="secno">5.4.2</span> <span class="content">Internal slots</span></a>
        <li><a href="#ts-default-controller-constructor"><span class="secno">5.4.3</span> <span class="content">new TransformStreamDefaultController()</span></a>
        <li>
         <a href="#ts-default-controller-prototype"><span class="secno">5.4.4</span> <span class="content">Properties of the <code class="idl"><span>TransformStreamDefaultController</span></code> prototype</span></a>
         <ol class="toc">
          <li><a href="#ts-default-controller-desired-size"><span class="secno">5.4.4.1</span> <span class="content">get
desiredSize</span></a>
          <li><a href="#ts-default-controller-enqueue"><span class="secno">5.4.4.2</span> <span class="content">enqueue(<var>chunk</var>)</span></a>
          <li><a href="#ts-default-controller-error"><span class="secno">5.4.4.3</span> <span class="content">error(<var>reason</var>)</span></a>
          <li><a href="#ts-default-controller-terminate"><span class="secno">5.4.4.4</span> <span class="content">terminate()</span></a>
         </ol>
       </ol>
      <li>
       <a href="#ts-default-controller-abstract-ops"><span class="secno">5.5</span> <span class="content">Transform stream default controller abstract operations</span></a>
       <ol class="toc">
        <li><a href="#is-transform-stream-default-controller"><span class="secno">5.5.1</span> <span class="content">IsTransformStreamDefaultController ( <var>x</var> )</span></a>
        <li><a href="#set-up-transform-stream-default-controller"><span class="secno">5.5.2</span> <span class="content">SetUpTransformStreamDefaultController ( <var>stream</var>, <var>controller</var>, <var>transformAlgorithm</var>, <var>flushAlgorithm</var> )</span></a>
        <li><a href="#set-up-transform-stream-default-controller-from-transformer"><span class="secno">5.5.3</span> <span class="content">SetUpTransformStreamDefaultControllerFromTransformer ( <var>stream</var>, <var>transformer</var> )</span></a>
        <li><a href="#transform-stream-default-controller-clear-algorithms"><span class="secno">5.5.4</span> <span class="content">TransformStreamDefaultControllerClearAlgorithms ( <var>controller</var> )</span></a>
        <li><a href="#transform-stream-default-controller-enqueue"><span class="secno">5.5.5</span> <span class="content">TransformStreamDefaultControllerEnqueue ( <var>controller</var>, <var>chunk</var> )</span></a>
        <li><a href="#transform-stream-default-controller-error"><span class="secno">5.5.6</span> <span class="content">TransformStreamDefaultControllerError ( <var>controller</var>, <var>e</var> )</span></a>
        <li><a href="#transform-stream-default-controller-perform-transform"><span class="secno">5.5.7</span> <span class="content">TransformStreamDefaultControllerPerformTransform ( <var>controller</var>, <var>chunk</var> )</span></a>
        <li><a href="#transform-stream-default-controller-terminate"><span class="secno">5.5.8</span> <span class="content">TransformStreamDefaultControllerTerminate ( <var>controller</var> )</span></a>
       </ol>
      <li>
       <a href="#ts-default-sink-abstract-ops"><span class="secno">5.6</span> <span class="content">Transform stream default sink abstract operations</span></a>
       <ol class="toc">
        <li><a href="#transform-stream-default-sink-write-algorithm"><span class="secno">5.6.1</span> <span class="content">TransformStreamDefaultSinkWriteAlgorithm ( <var>stream</var>, <var>chunk</var> )</span></a>
        <li><a href="#transform-stream-default-sink-abort-algorithm"><span class="secno">5.6.2</span> <span class="content">TransformStreamDefaultSinkAbortAlgorithm ( <var>stream</var>, <var>reason</var> )</span></a>
        <li><a href="#transform-stream-default-sink-close-algorithm"><span class="secno">5.6.3</span> <span class="content">TransformStreamDefaultSinkCloseAlgorithm( <var>stream</var> )</span></a>
       </ol>
      <li>
       <a href="#ts-default-source-abstract-ops"><span class="secno">5.7</span> <span class="content">Transform stream default source abstract operations</span></a>
       <ol class="toc">
        <li><a href="#transform-stream-default-source-pull"><span class="secno">5.7.1</span> <span class="content">TransformStreamDefaultSourcePullAlgorithm( <var>stream</var> )</span></a>
       </ol>
     </ol>
    <li>
     <a href="#other-stuff"><span class="secno">6</span> <span class="content">Other stream APIs and operations</span></a>
     <ol class="toc">
      <li>
       <a href="#qs"><span class="secno">6.1</span> <span class="content">Queuing strategies</span></a>
       <ol class="toc">
        <li><a href="#qs-api"><span class="secno">6.1.1</span> <span class="content">The queuing strategy API</span></a>
        <li>
         <a href="#blqs-class"><span class="secno">6.1.2</span> <span class="content">Class <code>ByteLengthQueuingStrategy</code></span></a>
         <ol class="toc">
          <li><a href="#blqs-class-definition"><span class="secno">6.1.2.1</span> <span class="content">Class definition</span></a>
          <li><a href="#blqs-constructor"><span class="secno">6.1.2.2</span> <span class="content">new
ByteLengthQueuingStrategy({ <var>highWaterMark</var> })</span></a>
          <li>
           <a href="#blqs-prototype"><span class="secno">6.1.2.3</span> <span class="content">Properties of the <code class="idl"><span>ByteLengthQueuingStrategy</span></code> prototype</span></a>
           <ol class="toc">
            <li><a href="#blqs-size"><span class="secno">6.1.2.3.1</span> <span class="content">size(<var>chunk</var>)</span></a>
           </ol>
         </ol>
        <li>
         <a href="#cqs-class"><span class="secno">6.1.3</span> <span class="content">Class <code>CountQueuingStrategy</code></span></a>
         <ol class="toc">
          <li><a href="#cqs-class-definition"><span class="secno">6.1.3.1</span> <span class="content">Class definition</span></a>
          <li><a href="#cqs-constructor"><span class="secno">6.1.3.2</span> <span class="content">new
CountQueuingStrategy({ <var>highWaterMark</var> })</span></a>
          <li>
           <a href="#cqs-prototype"><span class="secno">6.1.3.3</span> <span class="content">Properties of the <code class="idl"><span>CountQueuingStrategy</span></code> prototype</span></a>
           <ol class="toc">
            <li><a href="#cqs-size"><span class="secno">6.1.3.3.1</span> <span class="content">size()</span></a>
           </ol>
         </ol>
       </ol>
      <li>
       <a href="#queue-with-sizes"><span class="secno">6.2</span> <span class="content">Queue-with-sizes operations</span></a>
       <ol class="toc">
        <li><a href="#dequeue-value"><span class="secno">6.2.1</span> <span class="content">DequeueValue ( <var>container</var> )</span></a>
        <li><a href="#enqueue-value-with-size"><span class="secno">6.2.2</span> <span class="content">EnqueueValueWithSize ( <var>container</var>, <var>value</var>, <var>size</var> )</span></a>
        <li><a href="#peek-queue-value"><span class="secno">6.2.3</span> <span class="content">PeekQueueValue ( <var>container</var> )</span></a>
        <li><a href="#reset-queue"><span class="secno">6.2.4</span> <span class="content">ResetQueue ( <var>container</var> )</span></a>
       </ol>
      <li>
       <a href="#misc-abstract-ops"><span class="secno">6.3</span> <span class="content">Miscellaneous operations</span></a>
       <ol class="toc">
        <li><a href="#create-algorithm-from-underlying-method"><span class="secno">6.3.1</span> <span class="content">CreateAlgorithmFromUnderlyingMethod ( <var>underlyingObject</var>, <var>methodName</var>, <var>algoArgCount</var>, <var>extraArgs</var> )</span></a>
        <li><a href="#invoke-or-noop"><span class="secno">6.3.2</span> <span class="content">InvokeOrNoop ( <var>O</var>, <var>P</var>, <var>args</var> )</span></a>
        <li><a href="#is-finite-non-negative-number"><span class="secno">6.3.3</span> <span class="content">IsFiniteNonNegativeNumber ( <var>v</var> )</span></a>
        <li><a href="#is-non-negative-number"><span class="secno">6.3.4</span> <span class="content">IsNonNegativeNumber ( <var>v</var> )</span></a>
        <li><a href="#promise-call"><span class="secno">6.3.5</span> <span class="content">PromiseCall ( <var>F</var>, <var>V</var>, <var>args</var> )</span></a>
        <li><a href="#transfer-array-buffer"><span class="secno">6.3.6</span> <span class="content">TransferArrayBuffer ( <var>O</var> )</span></a>
        <li><a href="#validate-and-normalize-high-water-mark"><span class="secno">6.3.7</span> <span class="content">ValidateAndNormalizeHighWaterMark ( <var>highWaterMark</var> )</span></a>
        <li><a href="#make-size-algorithm-from-size-function"><span class="secno">6.3.8</span> <span class="content">MakeSizeAlgorithmFromSizeFunction ( <var>size</var> )</span></a>
       </ol>
     </ol>
    <li><a href="#globals"><span class="secno">7</span> <span class="content">Global properties</span></a>
    <li>
     <a href="#creating-examples"><span class="secno">8</span> <span class="content">Examples of creating streams</span></a>
     <ol class="toc">
      <li><a href="#example-rs-push-no-backpressure"><span class="secno">8.1</span> <span class="content">A readable stream with an underlying push source (no backpressure support)</span></a>
      <li><a href="#example-rs-push-backpressure"><span class="secno">8.2</span> <span class="content">A readable stream with an underlying push source and backpressure support</span></a>
      <li><a href="#example-rbs-push"><span class="secno">8.3</span> <span class="content">A readable byte stream with an underlying push source (no backpressure support)</span></a>
      <li><a href="#example-rs-pull"><span class="secno">8.4</span> <span class="content">A readable stream with an underlying pull source</span></a>
      <li><a href="#example-rbs-pull"><span class="secno">8.5</span> <span class="content">A readable byte stream with an underlying pull source</span></a>
      <li><a href="#example-ws-no-backpressure"><span class="secno">8.6</span> <span class="content">A writable stream with no backpressure or success signals</span></a>
      <li><a href="#example-ws-backpressure"><span class="secno">8.7</span> <span class="content">A writable stream with backpressure and success signals</span></a>
      <li><a href="#example-both"><span class="secno">8.8</span> <span class="content">A { readable, writable } stream pair wrapping the same underlying resource</span></a>
      <li><a href="#example-ts-lipfuzz"><span class="secno">8.9</span> <span class="content">A transform stream that replaces template tags</span></a>
      <li><a href="#example-ts-sync-mapper"><span class="secno">8.10</span> <span class="content">A transform stream created from a sync mapper function</span></a>
     </ol>
    <li><a href="#conventions"><span class="secno"></span> <span class="content">Conventions</span></a>
    <li><a href="#acks"><span class="secno"></span> <span class="content">Acknowledgments</span></a>
    <li>
     <a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
     <ol class="toc">
      <li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
      <li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
     </ol>
    <li>
     <a href="#references"><span class="secno"></span> <span class="content">References</span></a>
     <ol class="toc">
      <li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
      <li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
     </ol>
   </ol>
  </nav>
  <main>
   <h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content">Introduction</span><a class="self-link" href="#intro"></a></h2>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>Large swathes of the web platform are built on streaming data: that is, data that is created, processed, and consumed
in an incremental fashion, without ever reading all of it into memory. The Streams Standard provides a common set of
APIs for creating and interfacing with such streaming data, embodied in <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream">readable streams</a>, <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream">writable streams</a>, and <a data-link-type="dfn" href="#transform-stream" id="ref-for-transform-stream">transform streams</a>.</p>
    <p>These APIs have been designed to efficiently map to low-level I/O primitives, including specializations for byte streams
where appropriate. They allow easy composition of multiple streams into <a data-link-type="dfn" href="#pipe-chain" id="ref-for-pipe-chain">pipe chains</a>, or can be used directly via <a data-link-type="dfn" href="#reader" id="ref-for-reader">readers</a> and <a data-link-type="dfn" href="#writer" id="ref-for-writer">writers</a>. Finally, they are designed to automatically provide <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure">backpressure</a> and queuing.</p>
    <p>This standard provides the base stream primitives which other parts of the web platform can use to expose their
streaming data. For example, <a data-link-type="biblio" href="#biblio-fetch">[FETCH]</a> exposes <code class="idl"><a data-link-type="idl" href="https://fetch.spec.whatwg.org/#response" id="ref-for-response">Response</a></code> bodies as <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class">ReadableStream</a></code> instances. More generally, the
platform is full of streaming abstractions waiting to be expressed as streams: multimedia streams, file streams,
inter-global communication, and more benefit from being able to process data incrementally instead of buffering it all
into memory and processing it in one go. By providing the foundation for these streams to be exposed to developers, the
Streams Standard enables use cases like:</p>
    <ul>
     <li> Video effects: piping a readable video stream through a transform stream that applies effects in real time. 
     <li> Decompression: piping a file stream through a transform stream that selectively decompresses files from a <kbd>.tgz</kbd> archive, turning them into <code><a data-link-type="element" href="https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element" id="ref-for-the-img-element">img</a></code> elements as the user scrolls through an image gallery. 
     <li> Image decoding: piping an HTTP response stream through a transform stream that decodes bytes into bitmap data,
    and then through another transform that translates bitmaps into PNGs. If installed inside the <code class="idl"><a data-link-type="idl" href="https://w3c.github.io/ServiceWorker/#service-worker-global-scope-fetch-event" id="ref-for-service-worker-global-scope-fetch-event">fetch</a></code> hook of a service worker, this would allow developers to
    transparently polyfill new image formats. <a data-link-type="biblio" href="#biblio-service-workers">[SERVICE-WORKERS]</a> 
    </ul>
    <p>Web developers can also use the APIs described here to create their own streams, with the same APIs as those provided by
the platform. Other developers can then transparently compose platform-provided streams with those supplied by
libraries. In this way, the APIs described here provide unifying abstraction for all streams, encouraging an
ecosystem to grow around these shared and composable interfaces.</p>
   </div>
   <h2 class="heading settled" data-level="2" id="model"><span class="secno">2. </span><span class="content">Model</span><a class="self-link" href="#model"></a></h2>
   <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export id="chunk">chunk</dfn> is a single piece of data that is written to or read from a stream. It can be of any type;
streams can even contain chunks of different types. A chunk will often not be the most atomic unit of data for a given
stream; for example a byte stream might contain chunks consisting of 16 KiB <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-typedarray-objects" id="ref-for-sec-typedarray-objects">Uint8Array</a></code>s, instead of single bytes.</p>
   <h3 class="heading settled" data-level="2.1" id="rs-model"><span class="secno">2.1. </span><span class="content">Readable streams</span><a class="self-link" href="#rs-model"></a></h3>
   <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export id="readable-stream">readable stream</dfn> represents a source of data, from which you can read. In other words, data comes <em>out</em> of a readable stream. Concretely, a readable stream is an instance of the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①">ReadableStream</a></code> class.</p>
   <p>Although a readable stream can be created with arbitrary behavior, most readable streams wrap a lower-level I/O source,
called the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="underlying-source">underlying source</dfn>. There are two types of underlying source: push sources and pull sources.</p>
   <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="push source" data-noexport id="push-source">Push sources</dfn> push data at you, whether or not you are listening for it. They may also
provide a mechanism for pausing and resuming the flow of data. An example push source is a TCP socket, where data is
constantly being pushed from the OS level, at a rate that can be controlled by changing the TCP window size.</p>
   <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="pull source" data-noexport id="pull-source">Pull sources</dfn> require you to request data from them. The data may be available
synchronously, e.g. if it is held by the operating system’s in-memory buffers, or asynchronously, e.g. if it has to be
read from disk. An example pull source is a file handle, where you seek to specific locations and read specific amounts.</p>
   <p>Readable streams are designed to wrap both types of sources behind a single, unified interface. For web
developer–created streams, the implementation details of a source are provided by <a href="#underlying-source-api">an
object with certain methods and properties</a> that is passed to the <code class="idl"><a data-link-type="idl" href="#rs-constructor" id="ref-for-rs-constructor">ReadableStream()</a></code> constructor.</p>
   <p><a data-link-type="dfn" href="#chunk" id="ref-for-chunk">Chunks</a> are enqueued into the stream by the stream’s <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source">underlying source</a>. They can then be read one at a
time via the stream’s public interface, in particular by using a <a data-link-type="dfn" href="#reader" id="ref-for-reader①">readable stream reader</a> acquired using the
stream’s <code class="idl"><a data-link-type="idl" href="#rs-get-reader" id="ref-for-rs-get-reader">getReader()</a></code> method.</p>
   <p>Code that reads from a readable stream using its public interface is known as a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="consumer">consumer</dfn>.</p>
   <p>Consumers also have the ability to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="cancel a readable stream" data-noexport id="cancel-a-readable-stream">cancel</dfn> a readable stream, using its <code class="idl"><a data-link-type="idl" href="#rs-cancel" id="ref-for-rs-cancel">cancel()</a></code> method. This indicates that the consumer has lost interest in the stream, and will
immediately close the stream, throw away any queued <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①">chunks</a>, and execute any cancellation mechanism of the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①">underlying source</a>.</p>
   <p>Consumers can also <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="tee a readable stream" data-noexport id="tee-a-readable-stream">tee</dfn> a readable stream using its <code class="idl"><a data-link-type="idl" href="#rs-tee" id="ref-for-rs-tee">tee()</a></code> method. This will <a data-link-type="dfn" href="#lock" id="ref-for-lock">lock</a> the stream, making it no longer directly usable; however, it will
create two new streams, called <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="branches of a readable stream tee" data-noexport id="branches-of-a-readable-stream-tee">branches</dfn>, which can be consumed
independently.</p>
   <p>For streams representing bytes, an extended version of the <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①">readable stream</a> is provided to handle bytes
efficiently, in particular by minimizing copies. The <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②">underlying source</a> for such a readable stream is called
an <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="underlying-byte-source">underlying byte source</dfn>. A readable stream whose underlying source is an underlying byte source is
sometimes called a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="readable-byte-stream">readable byte stream</dfn>. Consumers of a readable byte stream can acquire a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers">BYOB reader</a> using the stream’s <code class="idl"><a data-link-type="idl" href="#rs-get-reader" id="ref-for-rs-get-reader①">getReader()</a></code> method.</p>
   <h3 class="heading settled" data-level="2.2" id="ws-model"><span class="secno">2.2. </span><span class="content">Writable streams</span><a class="self-link" href="#ws-model"></a></h3>
   <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export id="writable-stream">writable stream</dfn> represents a destination for data, into which you can write. In other words, data
goes <em>in</em> to a writable stream. Concretely, a writable stream is an instance of the <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class">WritableStream</a></code> class.</p>
   <p>Analogously to readable streams, most writable streams wrap a lower-level I/O sink, called the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="underlying-sink">underlying sink</dfn>. Writable streams work to abstract away some of the complexity of the underlying sink, by
queuing subsequent writes and only delivering them to the underlying sink one by one.</p>
   <p><a data-link-type="dfn" href="#chunk" id="ref-for-chunk②">Chunks</a> are written to the stream via its public interface, and are passed one at a time to the stream’s <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink">underlying sink</a>. For web developer-created streams, the implementation details of the sink are provided by <a href="#underlying-sink-api">an object with certain methods</a> that is passed to the <code class="idl"><a data-link-type="idl" href="#ws-constructor" id="ref-for-ws-constructor">WritableStream()</a></code> constructor.</p>
   <p>Code that writes into a writable stream using its public interface is known as a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="producer">producer</dfn>.</p>
   <p>Producers also have the ability to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="abort a writable stream" data-noexport id="abort-a-writable-stream">abort</dfn> a writable stream, using its <code class="idl"><a data-link-type="idl" href="#ws-abort" id="ref-for-ws-abort">abort()</a></code> method. This indicates that the producer believes something has gone wrong, and that future
writes should be discontinued. It puts the stream in an errored state, even without a signal from the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①">underlying
sink</a>, and it discards all writes in the stream’s <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues">internal queue</a>.</p>
   <h3 class="heading settled" data-level="2.3" id="ts-model"><span class="secno">2.3. </span><span class="content">Transform streams</span><a class="self-link" href="#ts-model"></a></h3>
   <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export id="transform-stream">transform stream</dfn> consists of a pair of streams: a <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①">writable stream</a>, known as its <dfn class="dfn-paneled" data-dfn-type="dfn" data-export id="writable-side">writable side</dfn>, and a <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream②">readable stream</a>, known as its <dfn class="dfn-paneled" data-dfn-type="dfn" data-export id="readable-side">readable side</dfn>. In a manner
specific to the transform stream in question, writes to the writable side result in new data being made available for
reading from the readable side.</p>
   <p>Concretely, any object with a <code>writable</code> property and a <code>readable</code> property can serve as a
transform stream. However, the standard <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class">TransformStream</a></code> class makes it much easier to create such a pair that is
properly entangled. It wraps a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="transformer">transformer</dfn>, which defines algorithms for the specific transformation to be
performed. For web developer–created streams, the implementation details of a transformer are provided by <a href="#transformer-api">an object with certain methods and properties</a> that is passed to the <code class="idl"><a data-link-type="idl" href="#ts-constructor" id="ref-for-ts-constructor">TransformStream()</a></code> constructor.</p>
   <p>An <dfn class="dfn-paneled" data-dfn-type="dfn" data-export id="identity-transform-stream">identity transform stream</dfn> is a type of transform stream which forwards all <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③">chunks</a> written
to its <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side">writable side</a> to its <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side">readable side</a>, without any changes. This can be useful in <a href="#example-transform-identity">a variety of scenarios</a>. By default, the <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①">TransformStream</a></code> constructor will
create an identity transform stream, when no <code class="idl"><a data-link-type="idl" href="#dom-transformer-transform" id="ref-for-dom-transformer-transform">transform()</a></code> method is present on the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer">transformer</a> object.</p>
   <p>Some examples of potential transform streams include:</p>
   <ul>
    <li>A GZIP compressor, to which uncompressed bytes are written and from which compressed bytes are read;
    <li>A video decoder, to which encoded bytes are written and from which uncompressed video frames are read;
    <li>A text decoder, to which bytes are written and from which strings are read;
    <li>A CSV-to-JSON converter, to which strings representing lines of a CSV file are written and from which
    corresponding JavaScript objects are read. 
   </ul>
   <h3 class="heading settled" data-level="2.4" id="pipe-chains"><span class="secno">2.4. </span><span class="content">Pipe chains and backpressure</span><a class="self-link" href="#pipe-chains"></a></h3>
   <p>Streams are primarily used by <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="piping">piping</dfn> them to each other. A readable stream can be piped directly to a
writable stream, using its <code class="idl"><a data-link-type="idl" href="#rs-pipe-to" id="ref-for-rs-pipe-to">pipeTo()</a></code> method, or it can be piped through one or more transform streams
first, using its <code class="idl"><a data-link-type="idl" href="#rs-pipe-through" id="ref-for-rs-pipe-through">pipeThrough()</a></code> method.</p>
   <p>A set of streams piped together in this way is referred to as a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="pipe-chain">pipe chain</dfn>. In a pipe chain, the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="original-source">original source</dfn> is the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source③">underlying source</a> of the first readable stream in the chain; the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="ultimate-sink">ultimate sink</dfn> is the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②">underlying sink</a> of the final writable stream in the chain.</p>
   <p>Once a pipe chain is constructed, it will propagate signals regarding how fast <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④">chunks</a> should flow through it. If
any step in the chain cannot yet accept chunks, it propagates a signal backwards through the pipe chain, until
eventually the original source is told to stop producing chunks so fast. This process of normalizing flow from the
original source according to how fast the chain can process chunks is called <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="backpressure">backpressure</dfn>.</p>
   <p>Concretely, the <a data-link-type="dfn" href="#original-source" id="ref-for-original-source">original source</a> is given the <code class="idl"><a data-link-type="idl" href="#rs-default-controller-desired-size" id="ref-for-rs-default-controller-desired-size">controller.desiredSize</a></code> (or <code class="idl"><a data-link-type="idl" href="#rbs-controller-desired-size" id="ref-for-rbs-controller-desired-size">byteController.desiredSize</a></code>) value, and can then adjust its rate of data
flow accordingly. This value is derived from the <code class="idl"><a data-link-type="idl" href="#default-writer-desired-size" id="ref-for-default-writer-desired-size">writer.desiredSize</a></code> corresponding to the <a data-link-type="dfn" href="#ultimate-sink" id="ref-for-ultimate-sink">ultimate sink</a>, which gets updated as the ultimate sink finishes writing <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤">chunks</a>. The <code class="idl"><a data-link-type="idl" href="#rs-pipe-to" id="ref-for-rs-pipe-to①">pipeTo()</a></code> method used to construct the chain automatically ensures this information propagates back
through the <a data-link-type="dfn" href="#pipe-chain" id="ref-for-pipe-chain①">pipe chain</a>.</p>
   <p>When <a data-link-type="dfn" href="#tee-a-readable-stream" id="ref-for-tee-a-readable-stream">teeing</a> a readable stream, the <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①">backpressure</a> signals from its two <a data-link-type="dfn" href="#branches-of-a-readable-stream-tee" id="ref-for-branches-of-a-readable-stream-tee">branches</a> will aggregate, such that if neither branch is read from, a
backpressure signal will be sent to the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source④">underlying source</a> of the original stream.</p>
   <p>Piping <a data-link-type="dfn" href="#lock" id="ref-for-lock①">locks</a> the readable and writable streams, preventing them from being manipulated for the duration of the
pipe operation. This allows the implementation to perform important optimizations, such as directly shuttling data from
the underlying source to the underlying sink while bypassing many of the intermediate queues.</p>
   <h3 class="heading settled" data-level="2.5" id="queuing-strategies"><span class="secno">2.5. </span><span class="content">Internal queues and queuing strategies</span><a class="self-link" href="#queuing-strategies"></a></h3>
   <p>Both readable and writable streams maintain <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="internal-queues">internal queues</dfn>, which they use for similar purposes. In the
case of a readable stream, the internal queue contains <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥">chunks</a> that have been enqueued by the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source⑤">underlying
source</a>, but not yet read by the consumer. In the case of a writable stream, the internal queue contains <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦">chunks</a> which have been written to the stream by the producer, but not yet processed and acknowledged by the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink③">underlying sink</a>.</p>
   <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="queuing-strategy">queuing strategy</dfn> is an object that determines how a stream should signal <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure②">backpressure</a> based on
the state of its <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues①">internal queue</a>. The queuing strategy assigns a size to each <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑧">chunk</a>, and compares the
total size of all chunks in the queue to a specified number, known as the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="high-water-mark">high water mark</dfn>. The resulting
difference, high water mark minus total size, is used to determine the <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="desired size to fill a stream’s internal queue" data-noexport id="desired-size-to-fill-a-streams-internal-queue">desired size to fill the stream’s queue</dfn>.</p>
   <p>For readable streams, an underlying source can use this desired size as a backpressure signal, slowing down chunk
generation so as to try to keep the desired size above or at zero. For writable streams, a producer can behave
similarly, avoiding writes that would cause the desired size to go negative.</p>
   <p><a href="#qs-api">Concretely</a>, a queuing strategy for web developer–created streams is given by any JavaScript object
with a <code><a data-link-type="dfn" href="#queuing-strategy-highwatermark" id="ref-for-queuing-strategy-highwatermark">highWaterMark</a></code> property. For byte streams the <code><a data-link-type="dfn" href="#queuing-strategy-highwatermark" id="ref-for-queuing-strategy-highwatermark①">highWaterMark</a></code> always has units of bytes. For other streams the default unit is <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑨">chunks</a>, but a <code><a data-link-type="functionish" href="#dom-queuing-strategy-size" id="ref-for-dom-queuing-strategy-size">size()</a></code> function can be included in the strategy object which returns the size
for a given chunk. This permits the <code><a data-link-type="dfn" href="#queuing-strategy-highwatermark" id="ref-for-queuing-strategy-highwatermark②">highWaterMark</a></code> to be specified in
arbitrary floating-point units.</p>
   <div class="example" id="example-simple-queuing-strategy">
    <a class="self-link" href="#example-simple-queuing-strategy"></a> A simple example of a queuing strategy would be one that assigns a size of one to each chunk, and has a high water
  mark of three. This would mean that up to three chunks could be enqueued in a readable stream, or three chunks
  written to a writable stream, before the streams are considered to be applying backpressure. 
    <p>In JavaScript, such a strategy could be written manually as <code>{ highWaterMark: 3, size() { return 1; }}</code>,
  or using the built-in <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class">CountQueuingStrategy</a></code> class, as <code>new CountQueuingStrategy({ highWaterMark: 3 })</code>.</p>
   </div>
   <h3 class="heading settled" data-level="2.6" id="locking"><span class="secno">2.6. </span><span class="content">Locking</span><a class="self-link" href="#locking"></a></h3>
   <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="reader|readable stream reader" data-noexport id="reader">readable stream reader</dfn>, or simply reader, is an object that allows
direct reading of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①⓪">chunks</a> from a <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream③">readable stream</a>. Without a reader, a <a data-link-type="dfn" href="#consumer" id="ref-for-consumer">consumer</a> can only perform
high-level operations on the readable stream: <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream">canceling</a> the stream, or <a data-link-type="dfn" href="#piping" id="ref-for-piping">piping</a> the readable stream to a writable stream. A reader is acquired via the stream’s <code class="idl"><a data-link-type="idl" href="#rs-get-reader" id="ref-for-rs-get-reader②">getReader()</a></code> method.</p>
   <p>A <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream">readable byte stream</a> has the ability to vend two types of readers: <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="default-readers">default readers</dfn> and <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="BYOB readers" data-noexport id="byob-readers">BYOB
readers</dfn>. BYOB ("bring your own buffer") readers allow reading into a developer-supplied buffer, thus minimizing
copies. A non-byte readable stream can only vend default readers. Default readers are instances of the <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class">ReadableStreamDefaultReader</a></code> class, while BYOB readers are instances of <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class">ReadableStreamBYOBReader</a></code>.</p>
   <p>Similarly, a <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="writer|writable stream writer" data-noexport id="writer">writable stream writer</dfn>, or simply writer, is an object that
allows direct writing of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①①">chunks</a> to a <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream②">writable stream</a>. Without a writer, a <a data-link-type="dfn" href="#producer" id="ref-for-producer">producer</a> can only perform
the high-level operations of <a data-link-type="dfn" href="#abort-a-writable-stream" id="ref-for-abort-a-writable-stream">aborting</a> the stream or <a data-link-type="dfn" href="#piping" id="ref-for-piping①">piping</a> a readable stream
to the writable stream. Writers are represented by the <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class">WritableStreamDefaultWriter</a></code> class.</p>
   <p class="note" role="note">Under the covers, these high-level operations actually use a reader or writer themselves.</p>
   <p>A given readable or writable stream only has at most one reader or writer at a time. We say in this case the stream is <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="lock|locked to a reader|locked to a writer" data-noexport id="lock">locked</dfn>, and that the reader or writer is <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="active|active reader|active writer" data-noexport id="active">active</dfn>. This state can be determined using the <code class="idl"><a data-link-type="idl" href="#rs-locked" id="ref-for-rs-locked">readableStream.locked</a></code> or <code class="idl"><a data-link-type="idl" href="#ws-locked" id="ref-for-ws-locked">writableStream.locked</a></code> properties.</p>
   <p>A reader or writer also has the capability to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="release a lock|release a read lock|release a write lock" data-noexport id="release-a-lock">release
its lock</dfn>, which makes it no longer active, and allows further readers or writers to be acquired. This is done via
the <code class="idl"><a data-link-type="idl" href="#default-reader-release-lock" id="ref-for-default-reader-release-lock">defaultReader.releaseLock()</a></code>, <code class="idl"><a data-link-type="idl" href="#byob-reader-release-lock" id="ref-for-byob-reader-release-lock">byobReader.releaseLock()</a></code>, or <code class="idl"><a data-link-type="idl" href="#default-writer-release-lock" id="ref-for-default-writer-release-lock">writer.releaseLock()</a></code> method, as appropriate.</p>
   <h2 class="heading settled" data-level="3" id="rs"><span class="secno">3. </span><span class="content">Readable streams</span><a class="self-link" href="#rs"></a></h2>
   <h3 class="heading settled" data-level="3.1" id="rs-intro"><span class="secno">3.1. </span><span class="content">Using readable streams</span><a class="self-link" href="#rs-intro"></a></h3>
   <div class="example" id="example-basic-pipe-to">
    <a class="self-link" href="#example-basic-pipe-to"></a> The simplest way to consume a readable stream is to simply <a data-link-type="dfn" href="#piping" id="ref-for-piping②">pipe</a> it to a <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream③">writable stream</a>.
  This ensures that <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure③">backpressure</a> is respected, and any errors (either writing or reading) are propagated through
  the chain: 
<pre><code class="lang-javascript highlight">readableStream<c- p>.</c->pipeTo<c- p>(</c->writableStream<c- p>)</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"All data successfully written!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Something went wrong!"</c-><c- p>,</c-> e<c- p>));</c->
</code></pre>
   </div>
   <div class="example" id="example-pipe-as-chunks-receiver">
    <a class="self-link" href="#example-pipe-as-chunks-receiver"></a> If you simply want to be alerted of each new chunk from a readable stream, you can <a data-link-type="dfn" href="#piping" id="ref-for-piping③">pipe</a> it to a
  new <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream④">writable stream</a> that you custom-create for that purpose: 
<pre><code class="lang-javascript highlight">readableStream<c- p>.</c->pipeTo<c- p>(</c-><c- k>new</c-> WritableStream<c- p>({</c->
  write<c- p>(</c->chunk<c- p>)</c-> <c- p>{</c->
    console<c- p>.</c->log<c- p>(</c-><c- u>"Chunk received"</c-><c- p>,</c-> chunk<c- p>);</c->
  <c- p>},</c->
  close<c- p>()</c-> <c- p>{</c->
    console<c- p>.</c->log<c- p>(</c-><c- u>"All data successfully read!"</c-><c- p>);</c->
  <c- p>},</c->
  abort<c- p>(</c->e<c- p>)</c-> <c- p>{</c->
    console<c- p>.</c->error<c- p>(</c-><c- u>"Something went wrong!"</c-><c- p>,</c-> e<c- p>);</c->
  <c- p>}</c->
<c- p>}));</c->
</code></pre>
    <p>By returning promises from your <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-write" id="ref-for-dom-underlying-sink-write">write()</a></code> implementation, you can signal <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure④">backpressure</a> to the
  readable stream.</p>
   </div>
   <div class="example" id="example-manual-read">
    <a class="self-link" href="#example-manual-read"></a> Although readable streams will usually be used by piping them to a writable stream, you can also read them directly by
  acquiring a <a data-link-type="dfn" href="#reader" id="ref-for-reader②">reader</a> and using its <code>read()</code> method to get successive chunks. For example, this code
  logs the next <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①②">chunk</a> in the stream, if available: 
<pre><code class="lang-javascript highlight"><c- kr>const</c-> reader <c- o>=</c-> readableStream<c- p>.</c->getReader<c- p>();</c->

reader<c- p>.</c->read<c- p>().</c->then<c- p>(</c->
  <c- p>({</c-> value<c- p>,</c-> done <c- p>})</c-> <c- p>=></c-> <c- p>{</c->
    <c- k>if</c-> <c- p>(</c->done<c- p>)</c-> <c- p>{</c->
      console<c- p>.</c->log<c- p>(</c-><c- u>"The stream was already closed!"</c-><c- p>);</c->
    <c- p>}</c-> <c- k>else</c-> <c- p>{</c->
      console<c- p>.</c->log<c- p>(</c->value<c- p>);</c->
    <c- p>}</c->
  <c- p>},</c->
  e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"The stream became errored and cannot be read from!"</c-><c- p>,</c-> e<c- p>)</c->
<c- p>);</c->
</code></pre>
    <p>This more manual method of reading a stream is mainly useful for library authors building new high-level operations
  on streams, beyond the provided ones of <a data-link-type="dfn" href="#piping" id="ref-for-piping④">piping</a> and <a data-link-type="dfn" href="#tee-a-readable-stream" id="ref-for-tee-a-readable-stream①">teeing</a>.</p>
   </div>
   <div class="example" id="example-manual-read-bytes">
    <a class="self-link" href="#example-manual-read-bytes"></a> The above example showed using the readable stream’s <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers">default reader</a>. If the stream is a <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream①">readable byte
  stream</a>, you can also acquire a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers①">BYOB reader</a> for it, which allows more precise control over buffer
  allocation in order to avoid copies. For example, this code reads the first 1024 bytes from the stream into a single
  memory buffer: 
<pre><code class="lang-javascript highlight"><c- kr>const</c-> reader <c- o>=</c-> readableStream<c- p>.</c->getReader<c- p>({</c-> mode<c- o>:</c-> <c- u>"byob"</c-> <c- p>});</c->

<c- a>let</c-> startingAB <c- o>=</c-> <c- k>new</c-> ArrayBuffer<c- p>(</c-><c- mi>1024</c-><c- p>);</c->
readInto<c- p>(</c->startingAB<c- p>)</c->
  <c- p>.</c->then<c- p>(</c->buffer <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"The first 1024 bytes:"</c-><c- p>,</c-> buffer<c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Something went wrong!"</c-><c- p>,</c-> e<c- p>));</c->

<c- a>function</c-> readInto<c- p>(</c->buffer<c- p>,</c-> offset <c- o>=</c-> <c- mi>0</c-><c- p>)</c-> <c- p>{</c->
  <c- k>if</c-> <c- p>(</c->offset <c- o>===</c-> buffer<c- p>.</c->byteLength<c- p>)</c-> <c- p>{</c->
    <c- k>return</c-> Promise<c- p>.</c->resolve<c- p>(</c->buffer<c- p>);</c->
  <c- p>}</c->

  <c- kr>const</c-> view <c- o>=</c-> <c- k>new</c-> Uint8Array<c- p>(</c->buffer<c- p>,</c-> offset<c- p>,</c-> buffer<c- p>.</c->byteLength <c- o>-</c-> offset<c- p>);</c->
  <c- k>return</c-> reader<c- p>.</c->read<c- p>(</c->view<c- p>).</c->then<c- p>(</c->newView <c- p>=></c-> <c- p>{</c->
    <c- k>return</c-> readInto<c- p>(</c->newView<c- p>.</c->buffer<c- p>,</c-> offset <c- o>+</c-> newView<c- p>.</c->byteLength<c- p>);</c->
  <c- p>});</c->
<c- p>}</c->
</code></pre>
    <p>An important thing to note here is that the final <code>buffer</code> value is different from the <code>startingAB</code>, but it (and all intermediate buffers) shares the same backing memory allocation. At each
  step, the buffer is <a href="#transfer-array-buffer">transferred</a> to a new <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-arraybuffer-objects" id="ref-for-sec-arraybuffer-objects">ArrayBuffer</a></code> object. The <code>newView</code> is a new <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-typedarray-objects" id="ref-for-sec-typedarray-objects①">Uint8Array</a></code>, with that <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-arraybuffer-objects" id="ref-for-sec-arraybuffer-objects①">ArrayBuffer</a></code> object as its <code>buffer</code> property,
  the offset that bytes were written to as its <code>byteOffset</code> property, and the number of bytes that were
  written as its <code>byteLength</code> property.</p>
   </div>
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="3.2" data-lt="ReadableStream" id="rs-class"><span class="secno">3.2. </span><span class="content">Class <code>ReadableStream</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②">ReadableStream</a></code> class is a concrete instance of the general <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream④">readable stream</a> concept. It is
adaptable to any <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①③">chunk</a> type, and maintains an internal queue to keep track of data supplied by the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source⑥">underlying
source</a> but not yet read by any consumer.</p>
   <h4 class="heading settled" data-level="3.2.1" id="rs-class-definition"><span class="secno">3.2.1. </span><span class="content">Class definition</span><a class="self-link" href="#rs-class-definition"></a></h4>
   <p><em>This section is non-normative.</em></p>
   <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③">ReadableStream</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it would look
like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> ReadableStream <c- p>{</c->
  <a href="#rs-constructor" id="ref-for-rs-constructor⑤">constructor</a><c- p>(</c-><a href="#underlying-source-api">underlyingSource</a> <c- o>=</c-> <c- p>{},</c-> <a href="#qs-api">strategy</a> <c- o>=</c-> <c- p>{})</c->

  get <a href="#rs-locked" id="ref-for-rs-locked①">locked</a><c- p>()</c->

  <a href="#rs-cancel" id="ref-for-rs-cancel④">cancel</a><c- p>(</c->reason<c- p>)</c->
  <a href="#rs-get-iterator" id="ref-for-rs-get-iterator">getIterator</a><c- p>({</c-> preventCancel <c- p>}</c-> <c- o>=</c-> <c- p>{})</c->
  <a href="#rs-get-reader" id="ref-for-rs-get-reader⑥">getReader</a><c- p>({</c-> mode <c- p>}</c-> <c- o>=</c-> <c- p>{})</c->
  <a href="#rs-pipe-through" id="ref-for-rs-pipe-through②">pipeThrough</a><c- p>({</c-> writable<c- p>,</c-> readable <c- p>},</c->
              <c- p>{</c-> preventClose<c- p>,</c-> preventAbort<c- p>,</c-> preventCancel<c- p>,</c-> signal <c- p>}</c-> <c- o>=</c-> <c- p>{})</c->
  <a href="#rs-pipe-to" id="ref-for-rs-pipe-to⑥">pipeTo</a><c- p>(</c->dest<c- p>,</c-> <c- p>{</c-> preventClose<c- p>,</c-> preventAbort<c- p>,</c-> preventCancel<c- p>,</c-> signal <c- p>}</c-> <c- o>=</c-> <c- p>{})</c->
  <a href="#rs-tee" id="ref-for-rs-tee①">tee</a><c- p>()</c->

  <a href="#rs-asynciterator" id="ref-for-rs-asynciterator"><c- p>[</c->@@asyncIterator<c- p>]</c-></a><c- p>({</c-> preventCancel <c- p>}</c-> <c- o>=</c-> <c- p>{})</c->
<c- p>}</c->
</code></pre>
   <h4 class="heading settled" data-level="3.2.2" id="rs-internal-slots"><span class="secno">3.2.2. </span><span class="content">Internal slots</span><a class="self-link" href="#rs-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class④">ReadableStream</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[disturbed]] 
      <td class="non-normative">A boolean flag set to <emu-val>true</emu-val> when the stream has been read from or
      canceled 
     <tr>
      <td>[[readableStreamController]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class">ReadableStreamDefaultController</a></code> or <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class">ReadableByteStreamController</a></code> created with
    the ability to control the state and queue of this stream; also used for the <a href="#is-readable-stream">IsReadableStream</a> brand check 
     <tr>
      <td>[[reader]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class①">ReadableStreamDefaultReader</a></code> or <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class①">ReadableStreamBYOBReader</a></code> instance, if the stream
    is <a data-link-type="dfn" href="#lock" id="ref-for-lock②">locked to a reader</a>, or <emu-val>undefined</emu-val> if it is not 
     <tr>
      <td>[[state]] 
      <td class="non-normative">A string containing the stream’s current state, used internally; one of <code>"readable"</code>, <code>"closed"</code>, or <code>"errored"</code> 
     <tr>
      <td>[[storedError]] 
      <td class="non-normative">A value indicating how the stream failed, to be given as a failure reason or exception
      when trying to operate on an errored stream 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="constructor" data-export data-level="3.2.3" data-lt="ReadableStream(underlyingSource, strategy)" id="rs-constructor"><span class="secno">3.2.3. </span><span class="content">new
ReadableStream(<var>underlyingSource</var> = {}, <var>strategy</var> = {})</span></h4>
   <div class="note" role="note">
     The <code>underlyingSource</code> argument represents the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source⑦">underlying source</a>, as described in <a href="#underlying-source-api">§ 3.2.4 Underlying source API</a>. 
    <p>The <code>strategy</code> argument represents the stream’s <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy">queuing strategy</a>, as described in <a href="#qs-api">§ 6.1.1 The queuing strategy API</a>. If it
  is not provided, the default behavior will be the same as a <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class①">CountQueuingStrategy</a></code> with a <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark">high water mark</a> of 1.</p>
   </div>
    <emu-alg>
  1. Perform ! InitializeReadableStream(*this*).
  1. Let _size_ be ? GetV(_strategy_, `"size"`).
  1. Let _highWaterMark_ be ? GetV(_strategy_, `"highWaterMark"`).
  1. Let _type_ be ? GetV(_underlyingSource_, `"type"`).
  1. Let _typeString_ be ? ToString(_type_).
  1. If _typeString_ is `"bytes"`,
    1. If _size_ is not *undefined*, throw a *RangeError* exception.
    1. If _highWaterMark_ is *undefined*, let _highWaterMark_ be *0*.
    1. Set _highWaterMark_ to ? ValidateAndNormalizeHighWaterMark(_highWaterMark_).
    1. Perform ? SetUpReadableByteStreamControllerFromUnderlyingSource(*this*, _underlyingSource_, _highWaterMark_).
  1. Otherwise, if _type_ is *undefined*,
    1. Let _sizeAlgorithm_ be ? MakeSizeAlgorithmFromSizeFunction(_size_).
    1. If _highWaterMark_ is *undefined*, let _highWaterMark_ be *1*.
    1. Set _highWaterMark_ to ? ValidateAndNormalizeHighWaterMark(_highWaterMark_).
    1. Perform ? SetUpReadableStreamDefaultControllerFromUnderlyingSource(*this*, _underlyingSource_, _highWaterMark_,
       _sizeAlgorithm_).
  1. Otherwise, throw a *RangeError* exception.
</emu-alg> 
   <h4 class="heading settled" data-level="3.2.4" id="underlying-source-api"><span class="secno">3.2.4. </span><span class="content">Underlying source API</span><a class="self-link" href="#underlying-source-api"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>The <code class="idl"><a data-link-type="idl" href="#rs-constructor" id="ref-for-rs-constructor①">ReadableStream()</a></code> constructor accepts as its first argument a JavaScript object representing the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source⑧">underlying
source</a>. Such objects can contain any of the following properties:</p>
    <dl>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="underlying source" data-dfn-type="method" data-export id="dom-underlying-source-start"><code>start(<var>controller</var>)</code></dfn>
     <dd>
      <p>A function that is called immediately during creation of the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class⑤">ReadableStream</a></code>.</p>
      <p>Typically this is used adapt a <a data-link-type="dfn" href="#push-source" id="ref-for-push-source">push source</a> by setting up relevant event listeners, as in the example of <a href="#example-rs-push-no-backpressure">§ 8.1 A readable stream with an underlying push source (no backpressure support)</a>, or to acquire access to a <a data-link-type="dfn" href="#pull-source" id="ref-for-pull-source">pull source</a>, as in <a href="#example-rs-pull">§ 8.4 A readable stream with an underlying pull source</a>.</p>
      <p>If this setup process is asynchronous, it can return a promise to signal success or failure; a rejected promise
    will error the stream. Any thrown exceptions will be re-thrown by the <code class="idl"><a data-link-type="idl" href="#rs-constructor" id="ref-for-rs-constructor②">ReadableStream()</a></code> constructor.</p>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="underlying source" data-dfn-type="method" data-export id="dom-underlying-source-pull"><code>pull(<var>controller</var>)</code></dfn>
     <dd>
      <p>A function that is called whenever the stream’s <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues②">internal queue</a> of chunks becomes not full, i.e. whenever
    the queue’s <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue">desired size</a> becomes positive. Generally, it
    will be called repeatedly until the queue reaches its <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark①">high water mark</a> (i.e. until the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue①">desired size</a> becomes non-positive).</p>
      <p>For <a data-link-type="dfn" href="#push-source" id="ref-for-push-source①">push sources</a>, this can be used to resume a paused flow, as in <a href="#example-rs-push-backpressure">§ 8.2 A readable stream with an underlying push source and backpressure support</a>. For <a data-link-type="dfn" href="#pull-source" id="ref-for-pull-source①">pull sources</a>, it is used to acquire new <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①④">chunks</a> to enqueue into the stream, as in <a href="#example-rs-pull">§ 8.4 A readable stream with an underlying pull source</a>.</p>
      <p>This function will not be called until <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-start" id="ref-for-dom-underlying-source-start">start()</a></code> successfully completes. Additionally, it
    will only be called repeatedly if it enqueues at least one chunk or fulfills a BYOB request; a no-op <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-pull" id="ref-for-dom-underlying-source-pull">pull()</a></code> implementation will not be continually called.</p>
      <p>If the function returns a promise, then it will not be called again until that promise fulfills. (If the
    promise rejects, the stream will become errored.) This is mainly used in the case of pull sources, where the
    promise returned represents the process of acquiring a new chunk. Throwing an exception is treated the same as
    returning a rejected promise.</p>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="underlying source" data-dfn-type="method" data-export id="dom-underlying-source-cancel"><code>cancel(<var>reason</var>)</code></dfn>
     <dd>
      <p>A function that is called whenever the <a data-link-type="dfn" href="#consumer" id="ref-for-consumer①">consumer</a> <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream①">cancels</a> the stream,
    via <code class="idl"><a data-link-type="idl" href="#rs-cancel" id="ref-for-rs-cancel①">stream.cancel()</a></code>, <code class="idl"><a data-link-type="idl" href="#default-reader-cancel" id="ref-for-default-reader-cancel">defaultReader.cancel()</a></code>, or <code class="idl"><a data-link-type="idl" href="#byob-reader-cancel" id="ref-for-byob-reader-cancel">byobReader.cancel()</a></code>. It takes as its argument the same value as was passed to
    those methods by the consumer.</p>
      <p>Readable streams can additionally be canceled under certain conditions during <a data-link-type="dfn" href="#piping" id="ref-for-piping⑤">piping</a>; see the definition
    of the <code class="idl"><a data-link-type="idl" href="#rs-pipe-to" id="ref-for-rs-pipe-to②">pipeTo()</a></code> method for more details.</p>
      <p>For all streams, this is generally used to release access to the underlying resource; see for example <a href="#example-rs-push-no-backpressure">§ 8.1 A readable stream with an underlying push source (no backpressure support)</a>.</p>
      <p>If the shutdown process is asynchronous, it can return a promise to signal success or failure; the result will be
    communicated via the return value of the <code>cancel()</code> method that was called. Additionally, a rejected
    promise will error the stream, instead of letting it close. Throwing an exception is treated the same as returning
    a rejected promise.</p>
     <dt><dfn class="dfn-paneled" data-dfn-for="underlying source" data-dfn-type="dfn" data-noexport id="underlying-source-type"><code>type</code></dfn> (byte streams only)
     <dd>
      <p>Can be set to <code>"bytes"</code> to signal that the constructed <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class⑥">ReadableStream</a></code> is a <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream②">readable byte
    stream</a>. This ensures that the resulting <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class⑦">ReadableStream</a></code> will successfully be able to vend <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers②">BYOB readers</a> via its <code class="idl"><a data-link-type="idl" href="#rs-get-reader" id="ref-for-rs-get-reader③">getReader()</a></code> method. It also affects the <code>controller</code> argument passed to the <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-start" id="ref-for-dom-underlying-source-start①">start()</a></code> and <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-pull" id="ref-for-dom-underlying-source-pull①">pull()</a></code> methods; see below.</p>
      <p>For an example of how to set up a readable byte stream, including using the different controller interface, see <a href="#example-rbs-push">§ 8.3 A readable byte stream with an underlying push source (no backpressure support)</a>.</p>
      <p>Setting any value other than <code>"bytes"</code> or <emu-val>undefined</emu-val> will cause the <code class="idl"><a data-link-type="idl" href="#rs-constructor" id="ref-for-rs-constructor③">ReadableStream()</a></code> constructor to throw an exception.</p>
     <dt><dfn class="dfn-paneled" data-dfn-for="underlying source" data-dfn-type="dfn" data-noexport id="underlying-source-autoallocatechunksize"><code>autoAllocateChunkSize</code></dfn> (byte streams only)
     <dd>
      <p>Can be set to a positive integer to cause the implementation to automatically allocate buffers for the
    underlying source code to write into. In this case, when a <a data-link-type="dfn" href="#consumer" id="ref-for-consumer②">consumer</a> is using a <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers①">default reader</a>, the
    stream implementation will automatically allocate an <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-arraybuffer-objects" id="ref-for-sec-arraybuffer-objects②">ArrayBuffer</a></code> of the given size, so that <code class="idl"><a data-link-type="idl" href="#rbs-controller-byob-request" id="ref-for-rbs-controller-byob-request">controller.byobRequest</a></code> is always present, as if the consumer was using
    a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers③">BYOB reader</a>.</p>
      <p>This is generally used to cut down on the amount of code needed to handle consumers that use default readers, as
    can be seen by comparing <a href="#example-rbs-push">§ 8.3 A readable byte stream with an underlying push source (no backpressure support)</a> without auto-allocation to <a href="#example-rbs-pull">§ 8.5 A readable byte stream with an underlying pull source</a> with
    auto-allocation.</p>
    </dl>
    <p>The type of the <code>controller</code> argument passed to the <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-start" id="ref-for-dom-underlying-source-start②">start()</a></code> and <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-pull" id="ref-for-dom-underlying-source-pull②">pull()</a></code> methods depends on the value of the <code><a data-link-type="dfn" href="#underlying-source-type" id="ref-for-underlying-source-type">type</a></code> option. If <code><a data-link-type="dfn" href="#underlying-source-type" id="ref-for-underlying-source-type①">type</a></code> is set to <code>undefined</code> (including via omission), <code>controller</code> will be a <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class①">ReadableStreamDefaultController</a></code>. If it’s set to <code>"bytes"</code>, <code>controller</code> will be a <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class①">ReadableByteStreamController</a></code>.</p>
   </div>
   <h4 class="heading settled" data-level="3.2.5" id="rs-prototype"><span class="secno">3.2.5. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class⑧">ReadableStream</a></code> prototype</span><a class="self-link" href="#rs-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="attribute" data-export data-level="3.2.5.1" data-lt="locked" id="rs-locked"><span class="secno">3.2.5.1. </span><span class="content">get locked</span></h5>
   <div class="note" role="note"> The <code>locked</code> getter returns whether or not the readable stream is <a data-link-type="dfn" href="#lock" id="ref-for-lock③">locked to a reader</a>. </div>
    <emu-alg>
  1. If ! IsReadableStream(*this*) is *false*, throw a *TypeError* exception.
  1. Return ! IsReadableStreamLocked(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="method" data-export data-level="3.2.5.2" data-lt="cancel(reason)" id="rs-cancel"><span class="secno">3.2.5.2. </span><span class="content">cancel(<var>reason</var>)</span></h5>
   <div class="note" role="note"> The <code>cancel</code> method <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream②">cancels</a> the stream, signaling a loss of interest
  in the stream by a consumer. The supplied <code>reason</code> argument will be given to the underlying source’s <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-cancel" id="ref-for-dom-underlying-source-cancel">cancel()</a></code> method, which might or might not use it. </div>
    <emu-alg>
  1. If ! IsReadableStream(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with">a promise rejected with</a> a *TypeError* exception.
  1. If ! IsReadableStreamLocked(*this*) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①">a promise rejected with</a> a *TypeError* exception.
  1. Return ! ReadableStreamCancel(*this*, _reason_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="method" data-export data-level="3.2.5.3" data-lt="getIterator({ preventCancel } = {})" id="rs-get-iterator"><span class="secno">3.2.5.3. </span><span class="content">getIterator({ <var>preventCancel</var> } = {})</span></h5>
   <div class="note" role="note"> The <code>getIterator</code> method returns an async iterator which can be used to consume the stream. The <code class="idl"><a data-link-type="idl" href="#rs-asynciterator-prototype-return" id="ref-for-rs-asynciterator-prototype-return">return()</a></code> method of this iterator object will, by default, <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream③">cancel</a> the stream; it will also release the reader. </div>
    <emu-alg>
  1. If ! IsReadableStream(*this*) is *false*, throw a *TypeError* exception.
  1. Let _reader_ be ? AcquireReadableStreamDefaultReader(*this*).
  1. Let _iterator_ be ! ObjectCreate(`<a data-link-type="idl" href="#rs-asynciterator-prototype" id="ref-for-rs-asynciterator-prototype">ReadableStreamAsyncIteratorPrototype</a>`).
  1. Set _iterator_.[[asyncIteratorReader]] to _reader_.
  1. Set _iterator_.[[preventCancel]] to ! ToBoolean(_preventCancel_).
  1. Return _iterator_.
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="method" data-export data-level="3.2.5.4" data-lt="getReader({ mode } = {})" id="rs-get-reader"><span class="secno">3.2.5.4. </span><span class="content">getReader({ <var>mode</var> } = {})</span></h5>
   <div class="note" role="note">
     The <code>getReader</code> method creates a reader of the type specified by the <code>mode</code> option and <a data-link-type="dfn" href="#lock" id="ref-for-lock④">locks</a> the stream to the new reader. While the stream is locked, no other reader can be
  acquired until this one is <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock">released</a>. 
    <p>This functionality is especially useful for creating abstractions that desire the ability to consume a stream in its
  entirety. By getting a reader for the stream, you can ensure nobody else can interleave reads with yours or cancel
  the stream, which would interfere with your abstraction.</p>
    <p>When <code>mode</code> is <emu-val>undefined</emu-val>, the method creates a <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers②">default reader</a> (an instance of <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class②">ReadableStreamDefaultReader</a></code>). The reader provides the ability to directly read individual <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①⑤">chunks</a> from the
  stream via the reader’s <code class="idl"><a data-link-type="idl" href="#default-reader-read" id="ref-for-default-reader-read">read()</a></code> method.</p>
    <p>When <code>mode</code> is <code>"byob"</code>, the <code>getReader</code> method creates a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers④">BYOB reader</a> (an
  instance of <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class②">ReadableStreamBYOBReader</a></code>). This feature only works on <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream③">readable byte streams</a>, i.e. streams which
  were constructed specifically with the ability to handle "bring your own buffer" reading. The reader provides the
  ability to directly read individual <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①⑥">chunks</a> from the stream via the reader’s <code class="idl"><a data-link-type="idl" href="#byob-reader-read" id="ref-for-byob-reader-read">read()</a></code> method, into developer-supplied buffers, allowing more precise control over allocation.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStream(*this*) is *false*, throw a *TypeError* exception.
  1. If _mode_ is *undefined*, return ? AcquireReadableStreamDefaultReader(*this*, *true*).
  1. Set _mode_ to ? ToString(_mode_).
  1. If _mode_ is `"byob"`, return ? AcquireReadableStreamBYOBReader(*this*, *true*).
  1. Throw a *RangeError* exception.
</emu-alg> 
   <div class="example" id="example-read-all-chunks">
    <a class="self-link" href="#example-read-all-chunks"></a> An example of an abstraction that might benefit from using a reader is a function like the following, which is
  designed to read an entire readable stream into memory as an array of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①⑦">chunks</a>. 
<pre><code class="lang-javascript highlight"><c- a>function</c-> readAllChunks<c- p>(</c->readableStream<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> reader <c- o>=</c-> readableStream<c- p>.</c->getReader<c- p>();</c->
  <c- kr>const</c-> chunks <c- o>=</c-> <c- p>[];</c->

  <c- k>return</c-> pump<c- p>();</c->

  <c- a>function</c-> pump<c- p>()</c-> <c- p>{</c->
    <c- k>return</c-> reader<c- p>.</c->read<c- p>().</c->then<c- p>(({</c-> value<c- p>,</c-> done <c- p>})</c-> <c- p>=></c-> <c- p>{</c->
      <c- k>if</c-> <c- p>(</c->done<c- p>)</c-> <c- p>{</c->
        <c- k>return</c-> chunks<c- p>;</c->
      <c- p>}</c->

      chunks<c- p>.</c->push<c- p>(</c->value<c- p>);</c->
      <c- k>return</c-> pump<c- p>();</c->
    <c- p>});</c->
  <c- p>}</c->
<c- p>}</c->
</code></pre>
    <p>Note how the first thing it does is obtain a reader, and from then on it uses the reader exclusively. This ensures
  that no other consumer can interfere with the stream, either by reading chunks or by <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream④">canceling</a> the stream.</p>
   </div>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="method" data-export data-level="3.2.5.5" data-lt="pipeThrough(transform, options)" id="rs-pipe-through"><span class="secno">3.2.5.5. </span><span class="content">pipeThrough({ <var>writable</var>, <var>readable</var> }, { <var>preventClose</var>, <var>preventAbort</var>, <var>preventCancel</var>, <var>signal</var> } = {})</span></h5>
   <div class="note" role="note">
     The <code>pipeThrough</code> method provides a convenient, chainable way of <a data-link-type="dfn" href="#piping" id="ref-for-piping⑥">piping</a> this <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream⑤">readable stream</a> through a <a data-link-type="dfn" href="#transform-stream" id="ref-for-transform-stream①">transform stream</a> (or any other <code>{ writable, readable }</code> pair). It simply pipes the stream
  into the writable side of the supplied pair, and returns the readable side for further use. 
    <p>Piping a stream will <a data-link-type="dfn" href="#lock" id="ref-for-lock⑤">lock</a> it for the duration of the pipe, preventing any other
  consumer from acquiring a reader.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStream(*this*) is *false*, throw a *TypeError* exception.
  1. If ! IsWritableStream(_writable_) is *false*, throw a *TypeError* exception.
  1. If ! IsReadableStream(_readable_) is *false*, throw a *TypeError* exception.
  1. Set _preventClose_ to ! ToBoolean(_preventClose_), set _preventAbort_ to ! ToBoolean(_preventAbort_), and set
     _preventCancel_ to ! ToBoolean(_preventCancel_).
  1. If _signal_ is not *undefined*, and _signal_ is not an instance of the `<a data-link-type="idl" href="https://dom.spec.whatwg.org/#abortsignal" id="ref-for-abortsignal">AbortSignal</a>` interface, throw a
     *TypeError* exception.
  1. If ! IsReadableStreamLocked(*this*) is *true*, throw a *TypeError* exception.
  1. If ! IsWritableStreamLocked(_writable_) is *true*, throw a *TypeError* exception.
  1. Let _promise_ be ! ReadableStreamPipeTo(*this*, _writable_, _preventClose_, _preventAbort_, _preventCancel_,
     _signal_).
  1. Set _promise_.[[PromiseIsHandled]] to *true*.
  1. Return _readable_.
</emu-alg> 
   <div class="example" id="example-pipe-chain">
    <a class="self-link" href="#example-pipe-chain"></a> A typical example of constructing <a data-link-type="dfn" href="#pipe-chain" id="ref-for-pipe-chain②">pipe chain</a> using <code class="idl"><a data-link-type="idl" href="#rs-pipe-through" id="ref-for-rs-pipe-through①">pipeThrough(transform, options)</a></code> would
  look like 
<pre><code class="lang-javascript highlight">httpResponseBody
  <c- p>.</c->pipeThrough<c- p>(</c->decompressorTransform<c- p>)</c->
  <c- p>.</c->pipeThrough<c- p>(</c->ignoreNonImageFilesTransform<c- p>)</c->
  <c- p>.</c->pipeTo<c- p>(</c->mediaGallery<c- p>);</c->
</code></pre>
   </div>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="method" data-export data-level="3.2.5.6" data-lt="pipeTo(dest, options)" id="rs-pipe-to"><span class="secno">3.2.5.6. </span><span class="content">pipeTo(<var>dest</var>,
{ <var>preventClose</var>, <var>preventAbort</var>, <var>preventCancel</var>, <var>signal</var> } = {})</span></h5>
   <div class="note" role="note">
     The <code>pipeTo</code> method <a data-link-type="dfn" href="#piping" id="ref-for-piping⑦">pipes</a> this <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream⑥">readable stream</a> to a given <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream⑤">writable
  stream</a>. The way in which the piping process behaves under various error conditions can be customized with a
  number of passed options. It returns a promise that fulfills when the piping process completes successfully, or
  rejects if any errors were encountered. 
    <p>Piping a stream will <a data-link-type="dfn" href="#lock" id="ref-for-lock⑥">lock</a> it for the duration of the pipe, preventing any other
  consumer from acquiring a reader.</p>
    <p>Errors and closures of the source and destination streams propagate as follows:</p>
    <ul>
     <li>
      <p>An error in the source <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream⑦">readable stream</a> will <a data-link-type="dfn" href="#abort-a-writable-stream" id="ref-for-abort-a-writable-stream①">abort</a> the destination <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream⑥">writable stream</a>, unless <code>preventAbort</code> is truthy. The returned promise will be rejected with the
    source’s error, or with any error that occurs during aborting the destination.</p>
     <li>
      <p>An error in the destination <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream⑦">writable stream</a> will <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream⑤">cancel</a> the
    source <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream⑧">readable stream</a>, unless <code>preventCancel</code> is truthy. The returned promise will be rejected
    with the destination’s error, or with any error that occurs during canceling the source.</p>
     <li>
      <p>When the source <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream⑨">readable stream</a> closes, the destination <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream⑧">writable stream</a> will be closed, unless <code>preventClose</code> is true. The returned promise will be fulfilled once this process completes, unless an
    error is encountered while closing the destination, in which case it will be rejected with that error.</p>
     <li>
      <p>If the destination <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream⑨">writable stream</a> starts out closed or closing, the source <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①⓪">readable stream</a> will be <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream⑥">canceled</a>, unless <code>preventCancel</code> is true. The returned
    promise will be rejected with an error indicating piping to a closed stream failed, or with any error that occurs
    during canceling the source.</p>
    </ul>
    <p>The <code>signal</code> option can be set to an <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#abortsignal" id="ref-for-abortsignal①">AbortSignal</a></code> to allow aborting an ongoing pipe operation via the
  corresponding <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#abortcontroller" id="ref-for-abortcontroller">AbortController</a></code>. In this case, the source <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①①">readable stream</a> will be <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream⑦">canceled</a>, and the destination <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①⓪">writable stream</a> <a data-link-type="dfn" href="#abort-a-writable-stream" id="ref-for-abort-a-writable-stream②">aborted</a>, unless
  the respective options <code>preventCancel</code> or <code>preventAbort</code> are set.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStream(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②">a promise rejected with</a> a *TypeError* exception.
  1. If ! IsWritableStream(_dest_) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③">a promise rejected with</a> a *TypeError* exception.
  1. Set _preventClose_ to ! ToBoolean(_preventClose_), set _preventAbort_ to ! ToBoolean(_preventAbort_), and set
     _preventCancel_ to ! ToBoolean(_preventCancel_).
  1. If _signal_ is not *undefined*, and _signal_ is not an instance of the `<a data-link-type="idl" href="https://dom.spec.whatwg.org/#abortsignal" id="ref-for-abortsignal②">AbortSignal</a>` interface, return
     <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④">a promise rejected with</a> a *TypeError* exception.
  1. If ! IsReadableStreamLocked(*this*) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤">a promise rejected with</a> a *TypeError* exception.
  1. If ! IsWritableStreamLocked(_dest_) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑥">a promise rejected with</a> a *TypeError* exception.
  1. Return ! ReadableStreamPipeTo(*this*, _dest_, _preventClose_, _preventAbort_, _preventCancel_, _signal_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="method" data-export data-level="3.2.5.7" data-lt="tee()" id="rs-tee"><span class="secno">3.2.5.7. </span><span class="content">tee()</span></h5>
   <div class="note" role="note">
     The <code>tee</code> method <a data-link-type="dfn" href="#tee-a-readable-stream" id="ref-for-tee-a-readable-stream②">tees</a> this readable stream, returning a two-element
  array containing the two resulting branches as new <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class⑨">ReadableStream</a></code> instances. 
    <p>Teeing a stream will <a data-link-type="dfn" href="#lock" id="ref-for-lock⑦">lock</a> it, preventing any other consumer from acquiring a reader.
  To <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream⑧">cancel</a> the stream, cancel both of the resulting branches; a composite
  cancellation reason will then be propagated to the stream’s <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source⑨">underlying source</a>.</p>
    <p>Note that the <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①⑧">chunks</a> seen in each branch will be the same object. If the chunks are not immutable, this could
  allow interference between the two branches.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStream(*this*) is *false*, throw a *TypeError* exception.
  1. Let _branches_ be ? ReadableStreamTee(*this*, *false*).
  1. Return ! CreateArrayFromList(_branches_).
</emu-alg> 
   <div class="example" id="example-tee-and-pipe">
    <a class="self-link" href="#example-tee-and-pipe"></a> Teeing a stream is most useful when you wish to let two independent consumers read from the stream in parallel,
  perhaps even at different speeds. For example, given a writable stream <code>cacheEntry</code> representing an
  on-disk file, and another writable stream <code>httpRequestBody</code> representing an upload to a remote server,
  you could pipe the same readable stream to both destinations at once: 
<pre><code class="lang-javascript highlight"><c- kr>const</c-> <c- p>[</c->forLocal<c- p>,</c-> forRemote<c- p>]</c-> <c- o>=</c-> readableStream<c- p>.</c->tee<c- p>();</c->

Promise<c- p>.</c->all<c- p>([</c->
  forLocal<c- p>.</c->pipeTo<c- p>(</c->cacheEntry<c- p>),</c->
  forRemote<c- p>.</c->pipeTo<c- p>(</c->httpRequestBody<c- p>)</c->
<c- p>])</c->
<c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"Saved the stream to the cache and also uploaded it!"</c-><c- p>))</c->
<c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Either caching or uploading failed: "</c-><c- p>,</c-> e<c- p>));</c->
</code></pre>
   </div>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStream" data-dfn-type="iterator" data-export data-level="3.2.5.8" data-lt="[@@asyncIterator]({ preventCancel } = {})" id="rs-asynciterator"><span class="secno">3.2.5.8. </span><span class="content">[@@asyncIterator]({ <var>preventCancel</var> } = {})</span></h5>
   <p class="note" role="note"> The <code>@@asyncIterator</code> method is an alias of <code class="idl"><a data-link-type="idl" href="#rs-get-iterator" id="ref-for-rs-get-iterator④">getIterator()</a></code>. </p>
   <p>The initial value of the <code>@@asyncIterator</code> method is the same function object as the initial value of the <code class="idl"><a data-link-type="idl" href="#rs-get-iterator" id="ref-for-rs-get-iterator①">getIterator()</a></code> method.</p>
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="3.3" data-lt="ReadableStreamAsyncIteratorPrototype" id="rs-asynciterator-prototype"><span class="secno">3.3. </span><span class="content">ReadableStreamAsyncIteratorPrototype</span></h3>
   <p><code class="idl"><a data-link-type="idl" href="#rs-asynciterator-prototype" id="ref-for-rs-asynciterator-prototype①">ReadableStreamAsyncIteratorPrototype</a></code> is an ordinary object that is used by <code class="idl"><a data-link-type="idl" href="#rs-get-iterator" id="ref-for-rs-get-iterator②">getIterator()</a></code> to
construct the objects it returns. Instances of <code class="idl"><a data-link-type="idl" href="#rs-asynciterator-prototype" id="ref-for-rs-asynciterator-prototype②">ReadableStreamAsyncIteratorPrototype</a></code> implement the <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-asynciterator-interface" id="ref-for-sec-asynciterator-interface">AsyncIterator</a></code> abstract interface from the JavaScript specification. <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a></p>
   <p>The <code class="idl"><a data-link-type="idl" href="#rs-asynciterator-prototype" id="ref-for-rs-asynciterator-prototype③">ReadableStreamAsyncIteratorPrototype</a></code> object must have its [[Prototype]] internal slot set to <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-asynciteratorprototype" id="ref-for-sec-asynciteratorprototype">%AsyncIteratorPrototype%</a></code>.</p>
   <h4 class="heading settled" data-level="3.3.1" id="default-reader-asynciterator-prototype-internal-slots"><span class="secno">3.3.1. </span><span class="content">Internal slots</span><a class="self-link" href="#default-reader-asynciterator-prototype-internal-slots"></a></h4>
   <p>Objects created by <code class="idl"><a data-link-type="idl" href="#rs-get-iterator" id="ref-for-rs-get-iterator③">getIterator()</a></code>, using <code class="idl"><a data-link-type="idl" href="#rs-asynciterator-prototype" id="ref-for-rs-asynciterator-prototype④">ReadableStreamAsyncIteratorPrototype</a></code> as their
prototype, are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[asyncIteratorReader]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class③">ReadableStreamDefaultReader</a></code> instance 
     <tr>
      <td>[[preventCancel]] 
      <td class="non-normative">A boolean value indicating if the stream will be <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream⑨">canceled</a> when the async iterator’s <code class="idl"><a data-link-type="idl" href="#rs-asynciterator-prototype-return" id="ref-for-rs-asynciterator-prototype-return①">return()</a></code> method is called 
   </table>
   <h4 class="heading settled idl-code" data-dfn-for="ReadableStreamAsyncIteratorPrototype" data-dfn-type="method" data-export data-level="3.3.2" data-lt="next()" id="rs-asynciterator-prototype-next"><span class="secno">3.3.2. </span><span class="content">next()</span><a class="self-link" href="#rs-asynciterator-prototype-next"></a></h4>
    <emu-alg>
  1. If ! IsReadableStreamAsyncIterator(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑦">a promise rejected with</a> a *TypeError* exception.
  1. Let _reader_ be *this*.[[asyncIteratorReader]].
  1. If _reader_.[[ownerReadableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑧">a promise rejected with</a> a *TypeError* exception.
  1. Return the result of <a data-link-type="dfn">reacting</a> to ! ReadableStreamDefaultReaderRead(_reader_) with the following fulfillment
     steps given the argument _result_:
    1. Assert: Type(_result_) is Object.
    1. Let _done_ be ! Get(_result_, `"done"`).
    1. Assert: Type(_done_) is Boolean.
    1. If _done_ is *true*, perform ! ReadableStreamReaderGenericRelease(_reader_).
    1. Let _value_ be ! Get(_result_, `"value"`).
    1. Return ! ReadableStreamCreateReadResult(_value_, _done_, *true*).
</emu-alg> 
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamAsyncIteratorPrototype" data-dfn-type="method" data-export data-level="3.3.3" data-lt="return(value)" id="rs-asynciterator-prototype-return"><span class="secno">3.3.3. </span><span class="content">return( <var>value</var> )</span></h4>
    <emu-alg>
  1. If ! IsReadableStreamAsyncIterator(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑨">a promise rejected with</a> a *TypeError* exception.
  1. Let _reader_ be *this*.[[asyncIteratorReader]].
  1. If _reader_.[[ownerReadableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①⓪">a promise rejected with</a> a *TypeError* exception.
  1. If _reader_.[[readRequests]] is not empty, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①①">a promise rejected with</a> a *TypeError* exception.
  1. If *this*.[[preventCancel]] is *false*, then:
    1. Let _result_ be ! ReadableStreamReaderGenericCancel(_reader_, _value_).
    1. Perform ! ReadableStreamReaderGenericRelease(_reader_).
    1. Return the result of <a data-link-type="dfn">reacting</a> to _result_ with a fulfillment step that returns !
    ReadableStreamCreateReadResult(_value_, *true*, *true*).
  1. Perform ! ReadableStreamReaderGenericRelease(_reader_).
  1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with">a promise resolved with</a> ! ReadableStreamCreateReadResult(_value_, *true*, *true*).
</emu-alg> 
   <h3 class="heading settled" data-level="3.4" id="rs-abstract-ops"><span class="secno">3.4. </span><span class="content">General readable stream abstract operations</span><a class="self-link" href="#rs-abstract-ops"></a></h3>
   <p>The following abstract operations, unlike most in this specification, are meant to be generally useful by other
specifications, instead of just being part of the implementation of this spec’s classes.</p>
   <h4 aoid="AcquireReadableStreamBYOBReader" class="heading settled" data-level="3.4.1" id="acquire-readable-stream-byob-reader" throws><span class="secno">3.4.1. </span><span class="content">AcquireReadableStreamBYOBReader ( <var>stream</var>[, <var>forAuthorCode</var> ] )</span><a class="self-link" href="#acquire-readable-stream-byob-reader"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that may wish to acquire a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers⑤">BYOB reader</a> for a given stream.</p>
    <emu-alg>
  1. If _forAuthorCode_ was not passed, set it to *false*.
  1. Let _reader_ be ? Construct(`<a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class③">ReadableStreamBYOBReader</a>`, « _stream_ »).
  1. Set _reader_.[[forAuthorCode]] to _forAuthorCode_.
  1. Return _reader_.
</emu-alg> 
   <h4 aoid="AcquireReadableStreamDefaultReader" class="heading settled" data-export data-level="3.4.2" id="acquire-readable-stream-reader" throws><span class="secno">3.4.2. </span><span class="content">AcquireReadableStreamDefaultReader ( <var>stream</var>[, <var>forAuthorCode</var> ] )</span><a class="self-link" href="#acquire-readable-stream-reader"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that may wish to acquire a <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers③">default
reader</a> for a given stream.</p>
   <p class="note" role="note">Other specifications ought to leave <var>forAuthorCode</var> as its default value of <emu-val>false</emu-val>, unless they are planning to directly expose the resulting <code>{ value, done }</code> object
to authors. See <a href="#rs-read-result-for-author-code">the note regarding ReadableStreamCreateReadResult</a> for more
information.</p>
    <emu-alg>
  1. If _forAuthorCode_ was not passed, set it to *false*.
  1. Let _reader_ be ? Construct(`<a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class④">ReadableStreamDefaultReader</a>`, « _stream_ »).
  1. Set _reader_.[[forAuthorCode]] to _forAuthorCode_.
  1. Return _reader_.
</emu-alg> 
   <h4 aoid="CreateReadableStream" class="heading settled" data-export data-level="3.4.3" id="create-readable-stream" throws><span class="secno">3.4.3. </span><span class="content">CreateReadableStream ( <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var> [, <var>highWaterMark</var> [, <var>sizeAlgorithm</var> ] ] )</span><a class="self-link" href="#create-readable-stream"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that wish to create <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①⓪">ReadableStream</a></code> instances. The <var>pullAlgorithm</var> and <var>cancelAlgorithm</var> algorithms must return
promises; if supplied, <var>sizeAlgorithm</var> must be an algorithm accepting <a data-link-type="dfn" href="#chunk" id="ref-for-chunk①⑨">chunk</a> objects and returning a
number; and if supplied, <var>highWaterMark</var> must be a non-negative, non-NaN number.</p>
   <p class="note" role="note">CreateReadableStream throws an exception if and only if the supplied <var>startAlgorithm</var> throws.</p>
    <emu-alg>
  1. If _highWaterMark_ was not passed, set it to *1*.
  1. If _sizeAlgorithm_ was not passed, set it to an algorithm that returns *1*.
  1. Assert: ! IsNonNegativeNumber(_highWaterMark_) is *true*.
  1. Let _stream_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①①">ReadableStream</a>`'s `prototype` property).
  1. Perform ! InitializeReadableStream(_stream_).
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class②">ReadableStreamDefaultController</a>`'s `prototype`
     property).
  1. Perform ? SetUpReadableStreamDefaultController(_stream_, _controller_, _startAlgorithm_, _pullAlgorithm_,
     _cancelAlgorithm_, _highWaterMark_, _sizeAlgorithm_).
  1. Return _stream_.
</emu-alg> 
   <h4 aoid="CreateReadableByteStream" class="heading settled" data-export data-level="3.4.4" id="create-readable-byte-stream" throws><span class="secno">3.4.4. </span><span class="content">CreateReadableByteStream ( <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var> [, <var>highWaterMark</var> [, <var>autoAllocateChunkSize</var> ] ] )</span><a class="self-link" href="#create-readable-byte-stream"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that wish to create <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①②">ReadableStream</a></code> instances of type "bytes". The <var>pullAlgorithm</var> and <var>cancelAlgorithm</var> algorithms must return
promises; if supplied, <var>highWaterMark</var> must be a non-negative, non-NaN number, and if supplied, <var>autoAllocateChunkSize</var> must be a positive integer.</p>
   <p class="note" role="note">CreateReadableByteStream throws an exception if and only if the supplied <var>startAlgorithm</var> throws.</p>
    <emu-alg>
  1. If _highWaterMark_ was not passed, set it to *0*.
  1. If _autoAllocateChunkSize_ was not passed, set it to *undefined*.
  1. Assert: ! IsNonNegativeNumber(_highWaterMark_) is *true*.
  1. If _autoAllocateChunkSize_ is not *undefined*,
    1. Assert: ! IsInteger(_autoAllocateChunkSize_) is *true*.
    1. Assert: _autoAllocateChunkSize_ is positive.
  1. Let _stream_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①③">ReadableStream</a>`'s `prototype` property).
  1. Perform ! InitializeReadableStream(_stream_).
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class②">ReadableByteStreamController</a>`'s `prototype`
     property).
  1. Perform ? SetUpReadableByteStreamController(_stream_, _controller_, _startAlgorithm_, _pullAlgorithm_,
     _cancelAlgorithm_, _highWaterMark_, _autoAllocateChunkSize_).
  1. Return _stream_.
</emu-alg> 
   <h4 aoid="InitializeReadableStream" class="heading settled" data-level="3.4.5" id="initialize-readable-stream" nothrow><span class="secno">3.4.5. </span><span class="content">InitializeReadableStream ( <var>stream</var> )</span><a class="self-link" href="#initialize-readable-stream"></a></h4>
    <emu-alg>
  1. Set _stream_.[[state]] to `"readable"`.
  1. Set _stream_.[[reader]] and _stream_.[[storedError]] to *undefined*.
  1. Set _stream_.[[disturbed]] to *false*.
</emu-alg> 
   <h4 aoid="IsReadableStream" class="heading settled" data-level="3.4.6" id="is-readable-stream" nothrow><span class="secno">3.4.6. </span><span class="content">IsReadableStream ( <var>x</var> )</span><a class="self-link" href="#is-readable-stream"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have a [[readableStreamController]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="IsReadableStreamDisturbed" class="heading settled" data-export data-level="3.4.7" id="is-readable-stream-disturbed" nothrow><span class="secno">3.4.7. </span><span class="content">IsReadableStreamDisturbed ( <var>stream</var> )</span><a class="self-link" href="#is-readable-stream-disturbed"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that may wish to query whether or not a
readable stream has ever been read from or canceled.</p>
    <emu-alg>
  1. Assert: ! IsReadableStream(_stream_) is *true*.
  1. Return _stream_.[[disturbed]].
</emu-alg> 
   <h4 aoid="IsReadableStreamLocked" class="heading settled" data-export data-level="3.4.8" id="is-readable-stream-locked" nothrow><span class="secno">3.4.8. </span><span class="content">IsReadableStreamLocked ( <var>stream</var> )</span><a class="self-link" href="#is-readable-stream-locked"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that may wish to query whether or not a
readable stream is <a data-link-type="dfn" href="#lock" id="ref-for-lock⑧">locked to a reader</a>.</p>
    <emu-alg>
  1. Assert: ! IsReadableStream(_stream_) is *true*.
  1. If _stream_.[[reader]] is *undefined*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="IsReadableStreamAsyncIterator" class="heading settled" data-export data-level="3.4.9" id="is-readable-stream-asynciterator" nothrow><span class="secno">3.4.9. </span><span class="content">IsReadableStreamAsyncIterator ( <var>x</var> )</span><a class="self-link" href="#is-readable-stream-asynciterator"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have a [[asyncIteratorReader]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="ReadableStreamTee" class="heading settled" data-export data-level="3.4.10" id="readable-stream-tee" throws><span class="secno">3.4.10. </span><span class="content">ReadableStreamTee ( <var>stream</var>, <var>cloneForBranch2</var> )</span><a class="self-link" href="#readable-stream-tee"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that may wish to <a data-link-type="dfn" href="#tee-a-readable-stream" id="ref-for-tee-a-readable-stream③">tee</a> a given readable stream.</p>
   <p>The second argument, <var>cloneForBranch2</var>, governs whether or not the data from the original stream will be cloned
(using HTML’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/structured-data.html#serializable-objects" id="ref-for-serializable-objects">serializable objects</a> framework) before appearing in the second of the returned branches. This is
useful for scenarios where both branches are to be consumed in such a way that they might otherwise interfere with each
other, such as by <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/structured-data.html#transferable-objects" id="ref-for-transferable-objects">transferring</a> their <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②⓪">chunks</a>. However, it does introduce a
noticeable asymmetry between the two branches, and limits the possible <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②①">chunks</a> to serializable ones. <a data-link-type="biblio" href="#biblio-html">[HTML]</a></p>
   <p class="note" role="note">In this standard ReadableStreamTee is always called with <var>cloneForBranch2</var> set to <emu-val>false</emu-val>; other specifications pass <emu-val>true</emu-val>.</p>
    <emu-alg>
  1. Assert: ! IsReadableStream(_stream_) is *true*.
  1. Assert: Type(_cloneForBranch2_) is Boolean.
  1. Let _reader_ be ? AcquireReadableStreamDefaultReader(_stream_).
  1. Let _reading_ be *false*.
  1. Let _canceled1_ be *false*.
  1. Let _canceled2_ be *false*.
  1. Let _reason1_ be *undefined*.
  1. Let _reason2_ be *undefined*.
  1. Let _branch1_ be *undefined*.
  1. Let _branch2_ be *undefined*.
  1. Let _cancelPromise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise">a new promise</a>.
  1. Let _pullAlgorithm_ be the following steps:
    1. If _reading_ is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①">a promise resolved with</a> *undefined*.
    1. Set _reading_ to *true*.
    1. Let _readPromise_ be the result of <a data-link-type="dfn">reacting</a> to ! ReadableStreamDefaultReaderRead(_reader_) with the
       following fulfillment steps given the argument _result_:
      1. Set _reading_ to *false*.
      1. Assert: Type(_result_) is Object.
      1. Let _done_ be ! Get(_result_, `"done"`).
      1. Assert: Type(_done_) is Boolean.
      1. If _done_ is *true*,
        1. If _canceled1_ is *false*,
          1. Perform ! ReadableStreamDefaultControllerClose(_branch1_.[[readableStreamController]]).
        1. If _canceled2_ is *false*,
          1. Perform ! ReadableStreamDefaultControllerClose(_branch2_.[[readableStreamController]]).
        1. Return.
      1. Let _value_ be ! Get(_result_, `"value"`).
      1. Let _value1_ and _value2_ be _value_.
      1. If _canceled2_ is *false* and _cloneForBranch2_ is *true*, set _value2_ to ? <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize" id="ref-for-structureddeserialize">StructuredDeserialize</a>(? <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/structured-data.html#structuredserialize" id="ref-for-structuredserialize">StructuredSerialize</a>(_value2_), the current Realm
         Record).
      1. If _canceled1_ is *false*, perform ?
         ReadableStreamDefaultControllerEnqueue(_branch1_.[[readableStreamController]], _value1_).
      1. If _canceled2_ is *false*, perform ?
         ReadableStreamDefaultControllerEnqueue(_branch2_.[[readableStreamController]], _value2_).
    1. Set _readPromise_.[[PromiseIsHandled]] to *true*.
    1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with②">a promise resolved with</a> *undefined*.
  1. Let _cancel1Algorithm_ be the following steps, taking a _reason_ argument:
    1. Set _canceled1_ to *true*.
    1. Set _reason1_ to _reason_.
    1. If _canceled2_ is *true*,
      1. Let _compositeReason_ be ! CreateArrayFromList(« _reason1_, _reason2_ »).
      1. Let _cancelResult_ be ! ReadableStreamCancel(_stream_, _compositeReason_).
      1. <a data-link-type="dfn">Resolve</a> _cancelPromise_ with _cancelResult_.
    1. Return _cancelPromise_.
  1. Let _cancel2Algorithm_ be the following steps, taking a _reason_ argument:
    1. Set _canceled2_ to *true*.
    1. Set _reason2_ to _reason_.
    1. If _canceled1_ is *true*,
      1. Let _compositeReason_ be ! CreateArrayFromList(« _reason1_, _reason2_ »).
      1. Let _cancelResult_ be ! ReadableStreamCancel(_stream_, _compositeReason_).
      1. <a data-link-type="dfn">Resolve</a> _cancelPromise_ with _cancelResult_.
    1. Return _cancelPromise_.
  1. Let _startAlgorithm_ be an algorithm that returns *undefined*.
  1. Set _branch1_ to ! CreateReadableStream(_startAlgorithm_, _pullAlgorithm_, _cancel1Algorithm_).
  1. Set _branch2_ to ! CreateReadableStream(_startAlgorithm_, _pullAlgorithm_, _cancel2Algorithm_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection">Upon rejection</a> of _reader_.[[closedPromise]] with reason _r_,
    1. Perform ! ReadableStreamDefaultControllerError(_branch1_.[[readableStreamController]], _r_).
    1. Perform ! ReadableStreamDefaultControllerError(_branch2_.[[readableStreamController]], _r_).
  1. Return « _branch1_, _branch2_ ».
</emu-alg> 
   <h4 aoid="ReadableStreamPipeTo" class="heading settled" data-export data-level="3.4.11" id="readable-stream-pipe-to" nothrow><span class="secno">3.4.11. </span><span class="content">ReadableStreamPipeTo ( <var>source</var>, <var>dest</var>, <var>preventClose</var>, <var>preventAbort</var>, <var>preventCancel</var>, <var>signal</var> )</span><a class="self-link" href="#readable-stream-pipe-to"></a></h4>
    <emu-alg>
  1. Assert: ! IsReadableStream(_source_) is *true*.
  1. Assert: ! IsWritableStream(_dest_) is *true*.
  1. Assert: Type(_preventClose_) is Boolean, Type(_preventAbort_) is Boolean, and Type(_preventCancel_) is Boolean.
  1. Assert: _signal_ is *undefined* or _signal_ is an instance of the `<a data-link-type="idl" href="https://dom.spec.whatwg.org/#abortsignal" id="ref-for-abortsignal③">AbortSignal</a>` interface.
  1. Assert: ! IsReadableStreamLocked(_source_) is *false*.
  1. Assert: ! IsWritableStreamLocked(_dest_) is *false*.
  1. If ! IsReadableByteStreamController(_source_.[[readableStreamController]]) is *true*, let _reader_ be either !
     AcquireReadableStreamBYOBReader(_source_) or ! AcquireReadableStreamDefaultReader(_source_), at the user agent’s
     discretion.
  1. Otherwise, let _reader_ be ! AcquireReadableStreamDefaultReader(_source_).
  1. Let _writer_ be ! AcquireWritableStreamDefaultWriter(_dest_).
  1. Set _source_.[[disturbed]] to *true*.
  1. Let _shuttingDown_ be *false*.
  1. Let _promise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise①">a new promise</a>.
  1. If _signal_ is not *undefined*,
    1. Let _abortAlgorithm_ be the following steps:
      1. Let _error_ be a new "`<a data-link-type="idl" href="https://heycam.github.io/webidl/#aborterror" id="ref-for-aborterror">AbortError</a>`" `<a data-link-type="idl" href="https://heycam.github.io/webidl/#idl-DOMException" id="ref-for-idl-DOMException">DOMException</a>`.
      1. Let _actions_ be an empty <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#ordered-set" id="ref-for-ordered-set">ordered set</a>.
      1. If _preventAbort_ is *false*, <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#set-append" id="ref-for-set-append">append</a> the following action to _actions_:
        1. If _dest_.[[state]] is `"writable"`, return ! WritableStreamAbort(_dest_, _error_).
        1. Otherwise, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with③">a promise resolved with</a> *undefined*.
      1. If _preventCancel_ is *false*, <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#set-append" id="ref-for-set-append①">append</a> the following action action to _actions_:
        1. If _source_.[[state]] is `"readable"`, return ! ReadableStreamCancel(_source_, _error_).
        1. Otherwise, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with④">a promise resolved with</a> *undefined*.
      1. <a href="#rs-pipeTo-shutdown-with-action">Shutdown with an action</a> consisting of
         <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#waiting-for-all-promise" id="ref-for-waiting-for-all-promise">getting a promise to wait for all</a> of the actions in _actions_, and with _error_.
    1. If _signal_’s <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#abortsignal-aborted-flag" id="ref-for-abortsignal-aborted-flag">aborted flag</a> is set, perform _abortAlgorithm_ and return _promise_.
    1. <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#abortsignal-add" id="ref-for-abortsignal-add">Add</a> _abortAlgorithm_ to _signal_.
  1. <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel" id="ref-for-in-parallel">In parallel</a> <span class="XXX">but not really; see <a href="https://github.com/whatwg/streams/issues/905">#905</a></span>, using _reader_ and _writer_, read all
     <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②②">chunks</a> from _source_ and write them to _dest_. Due to the locking provided by the reader and writer, the exact
     manner in which this happens is not observable to author code, and so there is flexibility in how this is done. The
     following constraints apply regardless of the exact algorithm used:
     * <strong>Public API must not be used:</strong> while reading or writing, or performing any of the operations
       below, the JavaScript-modifiable reader, writer, and stream APIs (i.e. methods on the appropriate prototypes)
       must not be used. Instead, the streams must be manipulated directly.
     * <strong>Backpressure must be enforced:</strong>
       * While WritableStreamDefaultWriterGetDesiredSize(_writer_) is ≤ *0* or is *null*, the user agent must not read
         from _reader_.
       * If _reader_ is a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers⑥">BYOB reader</a>, WritableStreamDefaultWriterGetDesiredSize(_writer_) should be used as a
         basis to determine the size of the chunks read from _reader_.
         <p class="note" role="note">It’s frequently inefficient to read chunks that are too small or too large. Other information
         might be factored in to determine the optimal chunk size.</p>
       * Reads or writes should not be delayed for reasons other than these backpressure signals.
         <p class="example" id="example-bad-backpressure"><a class="self-link" href="#example-bad-backpressure"></a>An implementation that waits for each write to successfully
         complete before proceeding to the next read/write operation violates this recommendation. In doing so, such an
         implementation makes the <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues③">internal queue</a> of _dest_ useless, as it ensures _dest_ always contains at most
         one queued <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②③">chunk</a>.</p>
     * <strong>Shutdown must stop activity:</strong> if _shuttingDown_ becomes *true*, the user agent must not
       initiate further reads from _reader_, and must only perform writes of already-read <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②④">chunks</a>, as described
       below. In particular, the user agent must check the below conditions before performing any reads or writes,
       since they might lead to immediate shutdown.
     * <strong>Error and close states must be propagated:</strong> the following conditions must be applied in order.
       1. <strong>Errors must be propagated forward:</strong> if _source_.[[state]] is or becomes `"errored"`, then
         1. If _preventAbort_ is *false*, <a href="#rs-pipeTo-shutdown-with-action">shutdown with an action</a> of !
            WritableStreamAbort(_dest_, _source_.[[storedError]]) and with _source_.[[storedError]].
         1. Otherwise, <a href="#rs-pipeTo-shutdown">shutdown</a> with _source_.[[storedError]].
       1. <strong>Errors must be propagated backward:</strong> if _dest_.[[state]] is or becomes `"errored"`, then
         1. If _preventCancel_ is *false*, <a href="#rs-pipeTo-shutdown-with-action">shutdown with an action</a> of !
            ReadableStreamCancel(_source_, _dest_.[[storedError]]) and with _dest_.[[storedError]].
         1. Otherwise, <a href="#rs-pipeTo-shutdown">shutdown</a> with _dest_.[[storedError]].
       1. <strong>Closing must be propagated forward:</strong> if _source_.[[state]] is or becomes `"closed"`, then
         1. If _preventClose_ is *false*, <a href="#rs-pipeTo-shutdown-with-action">shutdown with an action</a> of !
            WritableStreamDefaultWriterCloseWithErrorPropagation(_writer_).
         1. Otherwise, <a href="#rs-pipeTo-shutdown">shutdown</a>.
       1. <strong>Closing must be propagated backward:</strong> if ! WritableStreamCloseQueuedOrInFlight(_dest_) is *true*
         or _dest_.[[state]] is `"closed"`, then
         1. Assert: no <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②⑤">chunks</a> have been read or written.
         1. Let _destClosed_ be a new *TypeError*.
         1. If _preventCancel_ is *false*, <a href="#rs-pipeTo-shutdown-with-action">shutdown with an action</a> of !
            ReadableStreamCancel(_source_, _destClosed_) and with _destClosed_.
         1. Otherwise, <a href="#rs-pipeTo-shutdown">shutdown</a> with _destClosed_.
     * <i id="rs-pipeTo-shutdown-with-action">Shutdown with an action</i>: if any of the above requirements ask to
       shutdown with an action _action_, optionally with an error _originalError_, then:
       1. If _shuttingDown_ is *true*, abort these substeps.
       1. Set _shuttingDown_ to *true*.
       1. If _dest_.[[state]] is `"writable"` and ! WritableStreamCloseQueuedOrInFlight(_dest_) is *false*,
         1. If any <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②⑥">chunks</a> have been read but not yet written, write them to _dest_.
         1. Wait until every <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②⑦">chunk</a> that has been read has been written (i.e. the corresponding promises have
            settled).
       1. Let _p_ be the result of performing _action_.
       1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment">Upon fulfillment</a> of _p_, <a href="#rs-pipeTo-finalize">finalize</a>, passing along _originalError_ if
          it was given.
       1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection①">Upon rejection</a> of _p_ with reason _newError_, <a href="#rs-pipeTo-finalize">finalize</a> with
          _newError_.
     * <i id="rs-pipeTo-shutdown">Shutdown</i>: if any of the above requirements or steps ask to shutdown, optionally
       with an error _error_, then:
       1. If _shuttingDown_ is *true*, abort these substeps.
       1. Set _shuttingDown_ to *true*.
       1. If _dest_.[[state]] is `"writable"` and ! WritableStreamCloseQueuedOrInFlight(_dest_) is *false*,
         1. If any <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②⑧">chunks</a> have been read but not yet written, write them to _dest_.
         1. Wait until every <a data-link-type="dfn" href="#chunk" id="ref-for-chunk②⑨">chunk</a> that has been read has been written (i.e. the corresponding promises have
            settled).
       1. <a href="#rs-pipeTo-finalize">Finalize</a>, passing along _error_ if it was given.
     * <i id="rs-pipeTo-finalize">Finalize</i>: both forms of shutdown will eventually ask to finalize, optionally with
       an error _error_, which means to perform the following steps:
       1. Perform ! WritableStreamDefaultWriterRelease(_writer_).
       1. Perform ! ReadableStreamReaderGenericRelease(_reader_).
       1. If _signal_ is not *undefined*, <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#abortsignal-remove" id="ref-for-abortsignal-remove">remove</a> _abortAlgorithm_ from _signal_.
       1. If _error_ was given, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise">reject</a> _promise_ with _error_.
       1. Otherwise, <a data-link-type="dfn">resolve</a> _promise_ with *undefined*.
  1. Return _promise_.
</emu-alg> 
   <p class="note" role="note"> Various abstract operations performed here include object creation (often of promises), which usually would require
  specifying a realm for the created object. However, because of the locking, none of these objects can be observed by
  author code. As such, the realm used to create them does not matter. </p>
   <h3 class="heading settled" data-level="3.5" id="rs-abstract-ops-used-by-controllers"><span class="secno">3.5. </span><span class="content">The interface between readable streams and controllers</span><a class="self-link" href="#rs-abstract-ops-used-by-controllers"></a></h3>
   <p>In terms of specification factoring, the way that the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①④">ReadableStream</a></code> class encapsulates the behavior of
both simple readable streams and <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream④">readable byte streams</a> into a single class is by centralizing most of the
potentially-varying logic inside the two controller classes, <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class③">ReadableStreamDefaultController</a></code> and <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class③">ReadableByteStreamController</a></code>. Those classes define most of the stateful internal slots and abstract
operations for how a stream’s <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues④">internal queue</a> is managed and how it interfaces with its <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①⓪">underlying source</a> or <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source">underlying byte source</a>.</p>
   <p>Each controller class defines two internal methods, which are called by the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①⑤">ReadableStream</a></code> algorithms:</p>
   <dl>
    <dt><dfn class="dfn-paneled" data-dfn-type="abstract-op" data-export data-lt="[[CancelSteps]]" id="abstract-opdef-cancelsteps">[[CancelSteps]](<var>reason</var>)</dfn>
    <dd>The controller’s steps that run in reaction to the stream being <a data-link-type="dfn" href="#cancel-a-readable-stream" id="ref-for-cancel-a-readable-stream①⓪">canceled</a>,
  used to clean up the state stored in the controller and inform the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①①">underlying source</a>.
    <dt><dfn class="dfn-paneled" data-dfn-type="abstract-op" data-export data-lt="[[PullSteps]]" id="abstract-opdef-pullsteps">[[PullSteps]]()</dfn>
    <dd>The controller’s steps that run when a <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers④">default reader</a> is read from, used to pull from the controller any
  queued <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③⓪">chunks</a>, or pull from the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①②">underlying source</a> to get more chunks.
   </dl>
   <p>(These are defined as internal methods, instead of as abstract operations, so that they can be called polymorphically by
the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①⑥">ReadableStream</a></code> algorithms, without having to branch on which type of controller is present.)</p>
   <p>The rest of this section concerns abstract operations that go in the other direction: they are  used by the controller
implementations to affect their associated <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①⑦">ReadableStream</a></code> object. This translates internal state changes of the
controller into developer-facing results visible through the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①⑧">ReadableStream</a></code>'s public API.</p>
   <h4 aoid="ReadableStreamAddReadIntoRequest" class="heading settled" data-level="3.5.1" id="readable-stream-add-read-into-request" nothrow><span class="secno">3.5.1. </span><span class="content">ReadableStreamAddReadIntoRequest ( <var>stream</var> )</span><a class="self-link" href="#readable-stream-add-read-into-request"></a></h4>
    <emu-alg>
  1. Assert: ! IsReadableStreamBYOBReader(_stream_.[[reader]]) is *true*.
  1. Assert: _stream_.[[state]] is `"readable"` or `"closed"`.
  1. Let _promise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise②">a new promise</a>.
  1. Let _readIntoRequest_ be Record {[[promise]]: _promise_}.
  1. Append _readIntoRequest_ as the last element of _stream_.[[reader]].[[readIntoRequests]].
  1. Return _promise_.
</emu-alg> 
   <h4 aoid="ReadableStreamAddReadRequest" class="heading settled" data-level="3.5.2" id="readable-stream-add-read-request" nothrow><span class="secno">3.5.2. </span><span class="content">ReadableStreamAddReadRequest ( <var>stream</var> )</span><a class="self-link" href="#readable-stream-add-read-request"></a></h4>
    <emu-alg>
  1. Assert: ! IsReadableStreamDefaultReader(_stream_.[[reader]]) is *true*.
  1. Assert: _stream_.[[state]] is `"readable"`.
  1. Let _promise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise③">a new promise</a>.
  1. Let _readRequest_ be Record {[[promise]]: _promise_}.
  1. Append _readRequest_ as the last element of _stream_.[[reader]].[[readRequests]].
  1. Return _promise_.
</emu-alg> 
   <h4 aoid="ReadableStreamCancel" class="heading settled" data-export data-level="3.5.3" id="readable-stream-cancel" nothrow><span class="secno">3.5.3. </span><span class="content">ReadableStreamCancel ( <var>stream</var>, <var>reason</var> )</span><a class="self-link" href="#readable-stream-cancel"></a></h4>
    <emu-alg>
  1. Set _stream_.[[disturbed]] to *true*.
  1. If _stream_.[[state]] is `"closed"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with⑤">a promise resolved with</a> *undefined*.
  1. If _stream_.[[state]] is `"errored"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①②">a promise rejected with</a> _stream_.[[storedError]].
  1. Perform ! ReadableStreamClose(_stream_).
  1. Let _sourceCancelPromise_ be ! _stream_.[[readableStreamController]].<a data-link-type="abstract-op" href="#abstract-opdef-cancelsteps" id="ref-for-abstract-opdef-cancelsteps">[[CancelSteps]]</a>(_reason_).
  1. Return the result of <a data-link-type="dfn">reacting</a> to _sourceCancelPromise_ with a fulfillment step that returns *undefined*.
</emu-alg> 
   <h4 aoid="ReadableStreamClose" class="heading settled" data-level="3.5.4" id="readable-stream-close" nothrow><span class="secno">3.5.4. </span><span class="content">ReadableStreamClose ( <var>stream</var> )</span><a class="self-link" href="#readable-stream-close"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[state]] is `"readable"`.
  1. Set _stream_.[[state]] to `"closed"`.
  1. Let _reader_ be _stream_.[[reader]].
  1. If _reader_ is *undefined*, return.
  1. If ! IsReadableStreamDefaultReader(_reader_) is *true*,
    1. Repeat for each _readRequest_ that is an element of _reader_.[[readRequests]],
      1. <a data-link-type="dfn">Resolve</a> _readRequest_.[[promise]] with ! ReadableStreamCreateReadResult(*undefined*, *true*,
         _reader_.[[forAuthorCode]]).
    1. Set _reader_.[[readRequests]] to an empty List.
  1. <a data-link-type="dfn">Resolve</a> _reader_.[[closedPromise]] with *undefined*.
</emu-alg> 
   <div class="note" role="note"> The case where <var>stream</var>.[[state]] is <code>"closed"</code>, but <var>stream</var>.[[closeRequested]] is <emu-val>false</emu-val>, will happen if the stream was closed without its controller’s close method ever being
  called: i.e., if the stream was closed by a call to <code class="idl"><a data-link-type="idl" href="#rs-cancel" id="ref-for-rs-cancel②">cancel(reason)</a></code>. In this case we allow the
  controller’s <code>close</code> method to be called and silently do nothing, since the cancelation was outside the
  control of the underlying source. </div>
   <h4 aoid="ReadableStreamCreateReadResult" class="heading settled" data-level="3.5.5" id="readable-stream-create-read-result" nothrow><span class="secno">3.5.5. </span><span class="content">ReadableStreamCreateReadResult
( <var>value</var>, <var>done</var>, <var>forAuthorCode</var> )</span><a class="self-link" href="#readable-stream-create-read-result"></a></h4>
   <div class="note" id="rs-read-result-for-author-code" role="note">
    <a class="self-link" href="#rs-read-result-for-author-code"></a> When <var>forAuthorCode</var> is <emu-val>true</emu-val>, this abstract operation gives the same result
  as <a data-link-type="abstract-op" href="https://tc39.github.io/ecma262/#sec-createiterresultobject" id="ref-for-sec-createiterresultobject">CreateIterResultObject</a>(<var>value</var>, <var>done</var>). This provides the expected semantics
  when the object is to be returned from the <code class="idl"><a data-link-type="idl" href="#default-reader-read" id="ref-for-default-reader-read①">defaultReader.read()</a></code> or <code class="idl"><a data-link-type="idl" href="#byob-reader-read" id="ref-for-byob-reader-read①">byobReader.read()</a></code> methods. 
    <p>However, resolving promises with such objects will unavoidably result in an access to <code>Object.prototype.then</code>. For internal use, particularly in <code class="idl"><a data-link-type="idl" href="#rs-pipe-to" id="ref-for-rs-pipe-to③">pipeTo()</a></code> and in other
  specifications, it is important that reads not be observable by author code—even if that author code has tampered with <code>Object.prototype</code>. For this reason, a <emu-val>false</emu-val> value of <var>forAuthorCode</var> results
  in an object with a <emu-val>null</emu-val> prototype, keeping promise resolution unobservable.</p>
    <p>The underlying issue here is that reading from streams always uses promises for <code>{ value, done }</code> objects,
  even in specifications. Although it is conceivable we could rephrase all of the internal algorithms to not use
  promises and not use JavaScript objects, and instead only package up the results into promise-for-<code>{ value, done
  }</code> when a <code>read()</code> method is called, this would be a large undertaking, which we have not done. See <a href="https://github.com/whatwg/infra/issues/181">whatwg/infra#181</a> for more background on this subject.</p>
   </div>
    <emu-alg>
  1. Let _prototype_ be *null*.
  1. If _forAuthorCode_ is *true*, set _prototype_ to %ObjectPrototype%.
  1. Assert: Type(_done_) is Boolean.
  1. Let _obj_ be ObjectCreate(_prototype_).
  1. Perform CreateDataProperty(_obj_, `"value"`, _value_).
  1. Perform CreateDataProperty(_obj_, `"done"`, _done_).
  1. Return _obj_.
</emu-alg> 
   <h4 aoid="ReadableStreamError" class="heading settled" data-level="3.5.6" id="readable-stream-error" nothrow><span class="secno">3.5.6. </span><span class="content">ReadableStreamError ( <var>stream</var>, <var>e</var> )</span><a class="self-link" href="#readable-stream-error"></a></h4>
    <emu-alg>
  1. Assert: ! IsReadableStream(_stream_) is *true*.
  1. Assert: _stream_.[[state]] is `"readable"`.
  1. Set _stream_.[[state]] to `"errored"`.
  1. Set _stream_.[[storedError]] to _e_.
  1. Let _reader_ be _stream_.[[reader]].
  1. If _reader_ is *undefined*, return.
  1. If ! IsReadableStreamDefaultReader(_reader_) is *true*,
    1. Repeat for each _readRequest_ that is an element of _reader_.[[readRequests]],
      1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise①">Reject</a> _readRequest_.[[promise]] with _e_.
    1. Set _reader_.[[readRequests]] to a new empty List.
  1. Otherwise,
    1. Assert: ! IsReadableStreamBYOBReader(_reader_).
    1. Repeat for each _readIntoRequest_ that is an element of _reader_.[[readIntoRequests]],
      1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise②">Reject</a> _readIntoRequest_.[[promise]] with _e_.
    1. Set _reader_.[[readIntoRequests]] to a new empty List.
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise③">Reject</a> _reader_.[[closedPromise]] with _e_.
  1. Set _reader_.[[closedPromise]].[[PromiseIsHandled]] to *true*.
</emu-alg> 
   <h4 aoid="ReadableStreamFulfillReadIntoRequest" class="heading settled" data-level="3.5.7" id="readable-stream-fulfill-read-into-request" nothrow><span class="secno">3.5.7. </span><span class="content">ReadableStreamFulfillReadIntoRequest ( <var>stream</var>, <var>chunk</var>, <var>done</var> )</span><a class="self-link" href="#readable-stream-fulfill-read-into-request"></a></h4>
    <emu-alg>
  1. Let _reader_ be _stream_.[[reader]].
  1. Let _readIntoRequest_ be the first element of _reader_.[[readIntoRequests]].
  1. Remove _readIntoRequest_ from _reader_.[[readIntoRequests]], shifting all other elements downward (so that the
     second becomes the first, and so on).
  1. <a data-link-type="dfn">Resolve</a> _readIntoRequest_.[[promise]] with ! ReadableStreamCreateReadResult(_chunk_, _done_,
     _reader_.[[forAuthorCode]]).
</emu-alg> 
   <h4 aoid="ReadableStreamFulfillReadRequest" class="heading settled" data-level="3.5.8" id="readable-stream-fulfill-read-request" nothrow><span class="secno">3.5.8. </span><span class="content">ReadableStreamFulfillReadRequest ( <var>stream</var>, <var>chunk</var>, <var>done</var> )</span><a class="self-link" href="#readable-stream-fulfill-read-request"></a></h4>
    <emu-alg>
  1. Let _reader_ be _stream_.[[reader]].
  1. Let _readRequest_ be the first element of _reader_.[[readRequests]].
  1. Remove _readRequest_ from _reader_.[[readRequests]], shifting all other elements downward (so that the second
     becomes the first, and so on).
  1. <a data-link-type="dfn">Resolve</a> _readRequest_.[[promise]] with ! ReadableStreamCreateReadResult(_chunk_, _done_,
     _reader_.[[forAuthorCode]]).
</emu-alg> 
   <h4 aoid="ReadableStreamGetNumReadIntoRequests" class="heading settled" data-level="3.5.9" id="readable-stream-get-num-read-into-requests" nothrow><span class="secno">3.5.9. </span><span class="content">ReadableStreamGetNumReadIntoRequests ( <var>stream</var> )</span><a class="self-link" href="#readable-stream-get-num-read-into-requests"></a></h4>
    <emu-alg>
  1. Return the number of elements in _stream_.[[reader]].[[readIntoRequests]].
</emu-alg> 
   <h4 aoid="ReadableStreamGetNumReadRequests" class="heading settled" data-level="3.5.10" id="readable-stream-get-num-read-requests" nothrow><span class="secno">3.5.10. </span><span class="content">ReadableStreamGetNumReadRequests ( <var>stream</var> )</span><a class="self-link" href="#readable-stream-get-num-read-requests"></a></h4>
    <emu-alg>
  1. Return the number of elements in _stream_.[[reader]].[[readRequests]].
</emu-alg> 
   <h4 aoid="ReadableStreamHasBYOBReader" class="heading settled" data-level="3.5.11" id="readable-stream-has-byob-reader" nothrow><span class="secno">3.5.11. </span><span class="content">ReadableStreamHasBYOBReader ( <var>stream</var> )</span><a class="self-link" href="#readable-stream-has-byob-reader"></a></h4>
    <emu-alg>
  1. Let _reader_ be _stream_.[[reader]].
  1. If _reader_ is *undefined*, return *false*.
  1. If ! IsReadableStreamBYOBReader(_reader_) is *false*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="ReadableStreamHasDefaultReader" class="heading settled" data-level="3.5.12" id="readable-stream-has-default-reader" nothrow><span class="secno">3.5.12. </span><span class="content">ReadableStreamHasDefaultReader ( <var>stream</var> )</span><a class="self-link" href="#readable-stream-has-default-reader"></a></h4>
    <emu-alg>
  1. Let _reader_ be _stream_.[[reader]].
  1. If _reader_ is *undefined*, return *false*.
  1. If ! IsReadableStreamDefaultReader(_reader_) is *false*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="3.6" data-lt="ReadableStreamDefaultReader" id="default-reader-class"><span class="secno">3.6. </span><span class="content">Class <code>ReadableStreamDefaultReader</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class⑤">ReadableStreamDefaultReader</a></code> class represents a <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers⑤">default reader</a> designed to be vended by a <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class①⑨">ReadableStream</a></code> instance.</p>
   <h4 class="heading settled" data-level="3.6.1" id="default-reader-class-definition"><span class="secno">3.6.1. </span><span class="content">Class definition</span><a class="self-link" href="#default-reader-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class⑥">ReadableStreamDefaultReader</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it
would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> ReadableStreamDefaultReader <c- p>{</c->
  <a href="#default-reader-constructor" id="ref-for-default-reader-constructor">constructor<c- p>(</c->stream<c- p>)</c-></a>

  get <a href="#default-reader-closed" id="ref-for-default-reader-closed">closed</a><c- p>()</c->

  <a href="#default-reader-cancel" id="ref-for-default-reader-cancel①">cancel</a><c- p>(</c->reason<c- p>)</c->
  <a href="#default-reader-read" id="ref-for-default-reader-read④">read</a><c- p>()</c->
  <a href="#default-reader-release-lock" id="ref-for-default-reader-release-lock①">releaseLock</a><c- p>()</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="3.6.2" id="default-reader-internal-slots"><span class="secno">3.6.2. </span><span class="content">Internal slots</span><a class="self-link" href="#default-reader-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class⑦">ReadableStreamDefaultReader</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[closedPromise]] 
      <td class="non-normative">A promise returned by the reader’s <code class="idl"><a data-link-type="idl" href="#default-reader-closed" id="ref-for-default-reader-closed①">closed</a></code> getter 
     <tr>
      <td>[[forAuthorCode]] 
      <td class="non-normative">A boolean flag indicating whether this reader is visible to author code 
     <tr>
      <td>[[ownerReadableStream]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②⓪">ReadableStream</a></code> instance that owns this reader 
     <tr>
      <td>[[readRequests]] 
      <td class="non-normative">A List of promises returned by calls to the reader’s <code class="idl"><a data-link-type="idl" href="#default-reader-read" id="ref-for-default-reader-read②">read()</a></code> method that have not yet been resolved, due to the <a data-link-type="dfn" href="#consumer" id="ref-for-consumer③">consumer</a> requesting <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③①">chunks</a> sooner than they are available; also used for the <a href="#is-readable-stream-default-reader">IsReadableStreamDefaultReader</a> brand check 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultReader" data-dfn-type="constructor" data-export data-level="3.6.3" data-lt="ReadableStreamDefaultReader(stream)" id="default-reader-constructor"><span class="secno">3.6.3. </span><span class="content">new ReadableStreamDefaultReader(<var>stream</var>)</span></h4>
   <div class="note" role="note"> The <code>ReadableStreamDefaultReader</code> constructor is generally not meant to be used directly; instead, a
  stream’s <code class="idl"><a data-link-type="idl" href="#rs-get-reader" id="ref-for-rs-get-reader④">getReader()</a></code> method ought to be used. </div>
    <emu-alg>
  1. If ! IsReadableStream(_stream_) is *false*, throw a *TypeError* exception.
  1. If ! IsReadableStreamLocked(_stream_) is *true*, throw a *TypeError* exception.
  1. Perform ! ReadableStreamReaderGenericInitialize(*this*, _stream_).
  1. Set *this*.[[readRequests]] to a new empty List.
</emu-alg> 
   <h4 class="heading settled" data-level="3.6.4" id="default-reader-prototype"><span class="secno">3.6.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class⑧">ReadableStreamDefaultReader</a></code> prototype</span><a class="self-link" href="#default-reader-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultReader" data-dfn-type="attribute" data-export data-level="3.6.4.1" data-lt="closed" id="default-reader-closed"><span class="secno">3.6.4.1. </span><span class="content">get closed</span></h5>
   <div class="note" role="note"> The <code>closed</code> getter returns a promise that will be fulfilled when the stream becomes closed, or rejected if
  the stream ever errors or the reader’s lock is <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock①">released</a> before the stream finishes
  closing. </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultReader(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①③">a promise rejected with</a> a *TypeError* exception.
  1. Return *this*.[[closedPromise]].
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultReader" data-dfn-type="method" data-export data-level="3.6.4.2" data-lt="cancel(reason)" id="default-reader-cancel"><span class="secno">3.6.4.2. </span><span class="content">cancel(<var>reason</var>)</span></h5>
   <div class="note" role="note"> If the reader is <a data-link-type="dfn" href="#active" id="ref-for-active">active</a>, the <code>cancel</code> method behaves the same as that for the
  associated stream. </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultReader(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①④">a promise rejected with</a> a *TypeError* exception.
  1. If *this*.[[ownerReadableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①⑤">a promise rejected with</a> a *TypeError* exception.
  1. Return ! ReadableStreamReaderGenericCancel(*this*, _reason_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultReader" data-dfn-type="method" data-export data-level="3.6.4.3" data-lt="read()" id="default-reader-read"><span class="secno">3.6.4.3. </span><span class="content">read()</span></h5>
   <div class="note" role="note">
     The <code>read</code> method will return a promise that allows access to the next <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③②">chunk</a> from the stream’s
  internal queue, if available. 
    <ul>
     <li> If the chunk does become available, the promise will be fulfilled with an object of the form <code>{ value: theChunk, done: false }</code>. 
     <li> If the stream becomes closed, the promise will be fulfilled with an object of the form <code>{ value: undefined, done: true }</code>. 
     <li> If the stream becomes errored, the promise will be rejected with the relevant error. 
    </ul>
    <p>If reading a chunk causes the queue to become empty, more data will be pulled from the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①③">underlying source</a>.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultReader(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①⑥">a promise rejected with</a> a *TypeError* exception.
  1. If *this*.[[ownerReadableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①⑦">a promise rejected with</a> a *TypeError* exception.
  1. Return ! ReadableStreamDefaultReaderRead(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultReader" data-dfn-type="method" data-export data-level="3.6.4.4" data-lt="releaseLock()" id="default-reader-release-lock"><span class="secno">3.6.4.4. </span><span class="content">releaseLock()</span></h5>
   <div class="note" role="note">
     The <code>releaseLock</code> method <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock②">releases the reader’s lock</a> on the corresponding
  stream. After the lock is released, the reader is no longer <a data-link-type="dfn" href="#active" id="ref-for-active①">active</a>. If the associated
  stream is errored when the lock is released, the reader will appear errored in the same way from now on; otherwise,
  the reader will appear closed. 
    <p>A reader’s lock cannot be released while it still has a pending read request, i.e., if a promise returned by the
  reader’s <code class="idl"><a data-link-type="idl" href="#default-reader-read" id="ref-for-default-reader-read③">read()</a></code> method has not yet been settled. Attempting to do so will throw
  a <emu-val>TypeError</emu-val> and leave the reader locked to the stream.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultReader(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[ownerReadableStream]] is *undefined*, return.
  1. If *this*.[[readRequests]] is not empty, throw a *TypeError* exception.
  1. Perform ! ReadableStreamReaderGenericRelease(*this*).
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="3.7" data-lt="ReadableStreamBYOBReader" id="byob-reader-class"><span class="secno">3.7. </span><span class="content">Class <code>ReadableStreamBYOBReader</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class④">ReadableStreamBYOBReader</a></code> class represents a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers⑦">BYOB reader</a> designed to be vended by a <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②①">ReadableStream</a></code> instance.</p>
   <h4 class="heading settled" data-level="3.7.1" id="byob-reader-class-definition"><span class="secno">3.7.1. </span><span class="content">Class definition</span><a class="self-link" href="#byob-reader-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class⑤">ReadableStreamBYOBReader</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it
would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> ReadableStreamBYOBReader <c- p>{</c->
  <a href="#byob-reader-constructor" id="ref-for-byob-reader-constructor">constructor</a><c- p>(</c->stream<c- p>)</c->

  get <a href="#byob-reader-closed" id="ref-for-byob-reader-closed">closed</a><c- p>()</c->

  <a href="#byob-reader-cancel" id="ref-for-byob-reader-cancel①">cancel</a><c- p>(</c->reason<c- p>)</c->
  <a href="#byob-reader-read" id="ref-for-byob-reader-read④">read</a><c- p>(</c->view<c- p>)</c->
  <a href="#byob-reader-release-lock" id="ref-for-byob-reader-release-lock①">releaseLock</a><c- p>()</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="3.7.2" id="byob-reader-internal-slots"><span class="secno">3.7.2. </span><span class="content">Internal slots</span><a class="self-link" href="#byob-reader-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class⑥">ReadableStreamBYOBReader</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[closedPromise]] 
      <td class="non-normative">A promise returned by the reader’s <code class="idl"><a data-link-type="idl" href="#byob-reader-closed" id="ref-for-byob-reader-closed①">closed</a></code> getter 
     <tr>
      <td>[[forAuthorCode]] 
      <td class="non-normative">A boolean flag indicating whether this reader is visible to author code 
     <tr>
      <td>[[ownerReadableStream]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②②">ReadableStream</a></code> instance that owns this reader 
     <tr>
      <td>[[readIntoRequests]] 
      <td class="non-normative">A List of promises returned by calls to the reader’s <code class="idl"><a data-link-type="idl" href="#byob-reader-read" id="ref-for-byob-reader-read②">read(view)</a></code> method that have not yet been resolved, due to the <a data-link-type="dfn" href="#consumer" id="ref-for-consumer④">consumer</a> requesting <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③③">chunks</a> sooner than they are available; also used for the <a href="#is-readable-stream-byob-reader">IsReadableStreamBYOBReader</a> brand check 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBReader" data-dfn-type="constructor" data-export data-level="3.7.3" data-lt="ReadableStreamBYOBReader(stream)" id="byob-reader-constructor"><span class="secno">3.7.3. </span><span class="content">new
ReadableStreamBYOBReader(<var>stream</var>)</span></h4>
   <div class="note" role="note"> The <code>ReadableStreamBYOBReader</code> constructor is generally not meant to be used directly; instead, a stream’s <code class="idl"><a data-link-type="idl" href="#rs-get-reader" id="ref-for-rs-get-reader⑤">getReader()</a></code> method ought to be used. </div>
    <emu-alg>
  1. If ! IsReadableStream(_stream_) is *false*, throw a *TypeError* exception.
  1. If ! IsReadableByteStreamController(_stream_.[[readableStreamController]]) is *false*, throw a *TypeError* exception.
  1. If ! IsReadableStreamLocked(_stream_) is *true*, throw a *TypeError* exception.
  1. Perform ! ReadableStreamReaderGenericInitialize(*this*, _stream_).
  1. Set *this*.[[readIntoRequests]] to a new empty List.
</emu-alg> 
   <h4 class="heading settled" data-level="3.7.4" id="byob-reader-prototype"><span class="secno">3.7.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class⑦">ReadableStreamBYOBReader</a></code> prototype</span><a class="self-link" href="#byob-reader-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBReader" data-dfn-type="attribute" data-export data-level="3.7.4.1" data-lt="closed" id="byob-reader-closed"><span class="secno">3.7.4.1. </span><span class="content">get closed</span></h5>
   <div class="note" role="note"> The <code>closed</code> getter returns a promise that will be fulfilled when the stream becomes closed, or rejected if
  the stream ever errors or the reader’s lock is <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock③">released</a> before the stream finishes
  closing. </div>
    <emu-alg>
  1. If ! IsReadableStreamBYOBReader(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①⑧">a promise rejected with</a> a *TypeError* exception.
  1. Return *this*.[[closedPromise]].
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBReader" data-dfn-type="method" data-export data-level="3.7.4.2" data-lt="cancel(reason)" id="byob-reader-cancel"><span class="secno">3.7.4.2. </span><span class="content">cancel(<var>reason</var>)</span></h5>
   <div class="note" role="note"> If the reader is <a data-link-type="dfn" href="#active" id="ref-for-active②">active</a>, the <code>cancel</code> method behaves the same as that for the
  associated stream. </div>
    <emu-alg>
  1. If ! IsReadableStreamBYOBReader(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with①⑨">a promise rejected with</a> a *TypeError* exception.
  1. If *this*.[[ownerReadableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②⓪">a promise rejected with</a> a *TypeError* exception.
  1. Return ! ReadableStreamReaderGenericCancel(*this*, _reason_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBReader" data-dfn-type="method" data-export data-level="3.7.4.3" data-lt="read(view)" id="byob-reader-read"><span class="secno">3.7.4.3. </span><span class="content">read(<var>view</var>)</span></h5>
   <div class="note" role="note">
     The <code>read</code> method will write read bytes into <code>view</code> and return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with⑥">a promise resolved with</a> a
  possibly transferred buffer as described below. 
    <ul>
     <li> If the chunk does become available, the promise will be fulfilled with an object of the form <code>{ value: theChunk, done: false }</code>. 
     <li> If the stream becomes closed, the promise will be fulfilled with an object of the form <code>{ value: undefined, done: true }</code>. 
     <li> If the stream becomes errored, the promise will be rejected with the relevant error. 
    </ul>
    <p>If reading a chunk causes the queue to become empty, more data will be pulled from the <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source①">underlying byte source</a>.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStreamBYOBReader(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②①">a promise rejected with</a> a *TypeError* exception.
  1. If *this*.[[ownerReadableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②②">a promise rejected with</a> a *TypeError* exception.
  1. If Type(_view_) is not Object, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②③">a promise rejected with</a> a *TypeError* exception.
  1. If _view_ does not have a [[ViewedArrayBuffer]] internal slot, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②④">a promise rejected with</a> a *TypeError*
     exception.
  1. If ! IsDetachedBuffer(_view_.[[ViewedArrayBuffer]]) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②⑤">a promise rejected with</a> a *TypeError*
     exception.
  1. If _view_.[[ByteLength]] is *0*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②⑥">a promise rejected with</a> a *TypeError* exception.
  1. Return ! ReadableStreamBYOBReaderRead(*this*, _view_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBReader" data-dfn-type="method" data-export data-level="3.7.4.4" data-lt="releaseLock()" id="byob-reader-release-lock"><span class="secno">3.7.4.4. </span><span class="content">releaseLock()</span></h5>
   <div class="note" role="note">
     The <code>releaseLock</code> method <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock④">releases the reader’s lock</a> on the corresponding
  stream. After the lock is released, the reader is no longer <a data-link-type="dfn" href="#active" id="ref-for-active③">active</a>. If the associated
  stream is errored when the lock is released, the reader will appear errored in the same way from now on; otherwise,
  the reader will appear closed. 
    <p>A reader’s lock cannot be released while it still has a pending read request, i.e., if a promise returned by the
  reader’s <code class="idl"><a data-link-type="idl" href="#byob-reader-read" id="ref-for-byob-reader-read③">read()</a></code> method has not yet been settled. Attempting to do so will throw
  a <emu-val>TypeError</emu-val> and leave the reader locked to the stream.</p>
   </div>
    <emu-alg>
  1. If ! IsReadableStreamBYOBReader(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[ownerReadableStream]] is *undefined*, return.
  1. If *this*.[[readIntoRequests]] is not empty, throw a *TypeError* exception.
  1. Perform ! ReadableStreamReaderGenericRelease(*this*).
</emu-alg> 
   <h3 class="heading settled" data-level="3.8" id="rs-reader-abstract-ops"><span class="secno">3.8. </span><span class="content">Readable stream reader abstract operations</span><a class="self-link" href="#rs-reader-abstract-ops"></a></h3>
   <h4 aoid="IsReadableStreamDefaultReader" class="heading settled" data-level="3.8.1" id="is-readable-stream-default-reader" nothrow><span class="secno">3.8.1. </span><span class="content">IsReadableStreamDefaultReader ( <var>x</var> )</span><a class="self-link" href="#is-readable-stream-default-reader"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have a [[readRequests]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="IsReadableStreamBYOBReader" class="heading settled" data-level="3.8.2" id="is-readable-stream-byob-reader" nothrow><span class="secno">3.8.2. </span><span class="content">IsReadableStreamBYOBReader ( <var>x</var> )</span><a class="self-link" href="#is-readable-stream-byob-reader"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have a [[readIntoRequests]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="ReadableStreamReaderGenericCancel" class="heading settled" data-level="3.8.3" id="readable-stream-reader-generic-cancel" nothrow><span class="secno">3.8.3. </span><span class="content">ReadableStreamReaderGenericCancel ( <var>reader</var>, <var>reason</var> )</span><a class="self-link" href="#readable-stream-reader-generic-cancel"></a></h4>
    <emu-alg>
  1. Let _stream_ be _reader_.[[ownerReadableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Return ! ReadableStreamCancel(_stream_, _reason_).
</emu-alg> 
   <h4 aoid="ReadableStreamReaderGenericInitialize" class="heading settled" data-level="3.8.4" id="readable-stream-reader-generic-initialize" nothrow><span class="secno">3.8.4. </span><span class="content">ReadableStreamReaderGenericInitialize ( <var>reader</var>, <var>stream</var> )</span><a class="self-link" href="#readable-stream-reader-generic-initialize"></a></h4>
    <emu-alg>
  1. Set _reader_.[[forAuthorCode]] to *true*.
  1. Set _reader_.[[ownerReadableStream]] to _stream_.
  1. Set _stream_.[[reader]] to _reader_.
  1. If _stream_.[[state]] is `"readable"`,
    1. Set _reader_.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise④">a new promise</a>.
  1. Otherwise, if _stream_.[[state]] is `"closed"`,
    1. Set _reader_.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with⑦">a promise resolved with</a> *undefined*.
  1. Otherwise,
    1. Assert: _stream_.[[state]] is `"errored"`.
    1. Set _reader_.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②⑦">a promise rejected with</a> _stream_.[[storedError]].
    1. Set _reader_.[[closedPromise]].[[PromiseIsHandled]] to *true*.
</emu-alg> 
   <h4 aoid="ReadableStreamReaderGenericRelease" class="heading settled" data-level="3.8.5" id="readable-stream-reader-generic-release" nothrow><span class="secno">3.8.5. </span><span class="content">ReadableStreamReaderGenericRelease ( <var>reader</var> )</span><a class="self-link" href="#readable-stream-reader-generic-release"></a></h4>
    <emu-alg>
  1. Assert: _reader_.[[ownerReadableStream]] is not *undefined*.
  1. Assert: _reader_.[[ownerReadableStream]].[[reader]] is _reader_.
  1. If _reader_.[[ownerReadableStream]].[[state]] is `"readable"`, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise④">reject</a> _reader_.[[closedPromise]] with a *TypeError*
     exception.
  1. Otherwise, set _reader_.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②⑧">a promise rejected with</a> a *TypeError* exception.
  1. Set _reader_.[[closedPromise]].[[PromiseIsHandled]] to *true*.
  1. Set _reader_.[[ownerReadableStream]].[[reader]] to *undefined*.
  1. Set _reader_.[[ownerReadableStream]] to *undefined*.
</emu-alg> 
   <h4 aoid="ReadableStreamBYOBReaderRead" class="heading settled" data-level="3.8.6" id="readable-stream-byob-reader-read" nothrow><span class="secno">3.8.6. </span><span class="content">ReadableStreamBYOBReaderRead
( <var>reader</var>, <var>view</var> )</span><a class="self-link" href="#readable-stream-byob-reader-read"></a></h4>
    <emu-alg>
  1. Let _stream_ be _reader_.[[ownerReadableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Set _stream_.[[disturbed]] to *true*.
  1. If _stream_.[[state]] is `"errored"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with②⑨">a promise rejected with</a> _stream_.[[storedError]].
  1. Return ! ReadableByteStreamControllerPullInto(_stream_.[[readableStreamController]], _view_).
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultReaderRead" class="heading settled" data-export data-level="3.8.7" id="readable-stream-default-reader-read" nothrow><span class="secno">3.8.7. </span><span class="content">ReadableStreamDefaultReaderRead ( <var>reader</var> )</span><a class="self-link" href="#readable-stream-default-reader-read"></a></h4>
    <emu-alg>
  1. Let _stream_ be _reader_.[[ownerReadableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Set _stream_.[[disturbed]] to *true*.
  1. If _stream_.[[state]] is `"closed"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with⑧">a promise resolved with</a> !
     ReadableStreamCreateReadResult(*undefined*, *true*, _reader_.[[forAuthorCode]]).
  1. If _stream_.[[state]] is `"errored"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③⓪">a promise rejected with</a> _stream_.[[storedError]].
  1. Assert: _stream_.[[state]] is `"readable"`.
  1. Return ! _stream_.[[readableStreamController]].<a data-link-type="abstract-op" href="#abstract-opdef-pullsteps" id="ref-for-abstract-opdef-pullsteps">[[PullSteps]]</a>().
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="3.9" data-lt="ReadableStreamDefaultController" id="rs-default-controller-class"><span class="secno">3.9. </span><span class="content">Class <code>ReadableStreamDefaultController</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class④">ReadableStreamDefaultController</a></code> class has methods that allow control of a <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②③">ReadableStream</a></code>'s state and <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues⑤">internal queue</a>. When constructing a <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②④">ReadableStream</a></code> that is not a <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream⑤">readable byte stream</a>, the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①④">underlying source</a> is given a corresponding <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class⑤">ReadableStreamDefaultController</a></code> instance to manipulate.</p>
   <h4 class="heading settled" data-level="3.9.1" id="rs-default-controller-class-definition"><span class="secno">3.9.1. </span><span class="content">Class definition</span><a class="self-link" href="#rs-default-controller-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class⑥">ReadableStreamDefaultController</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>,
it would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> ReadableStreamDefaultController <c- p>{</c->
  <a href="#rs-default-controller-constructor" id="ref-for-rs-default-controller-constructor">constructor</a><c- p>()</c-> <c- c1>// always throws</c->

  get <a href="#rs-default-controller-desired-size" id="ref-for-rs-default-controller-desired-size③">desiredSize</a><c- p>()</c->

  <a href="#rs-default-controller-close" id="ref-for-rs-default-controller-close">close</a><c- p>()</c->
  <a href="#rs-default-controller-enqueue" id="ref-for-rs-default-controller-enqueue">enqueue</a><c- p>(</c->chunk<c- p>)</c->
  <a href="#rs-default-controller-error" id="ref-for-rs-default-controller-error">error</a><c- p>(</c->e<c- p>)</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="3.9.2" id="rs-default-controller-internal-slots"><span class="secno">3.9.2. </span><span class="content">Internal slots</span><a class="self-link" href="#rs-default-controller-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class⑦">ReadableStreamDefaultController</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[cancelAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm, taking one argument (the cancel reason), which communicates
      a requested cancelation to the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①⑤">underlying source</a> 
     <tr>
      <td>[[closeRequested]] 
      <td class="non-normative">A boolean flag indicating whether the stream has been closed by its <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①⑥">underlying
      source</a>, but still has <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③④">chunks</a> in its internal queue that have not yet been read 
     <tr>
      <td>[[controlledReadableStream]] 
      <td class="non-normative">The <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②⑤">ReadableStream</a></code> instance controlled 
     <tr>
      <td>[[pullAgain]] 
      <td class="non-normative">A boolean flag set to <emu-val>true</emu-val> if the stream’s mechanisms requested a call
      to the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①⑦">underlying source</a>’s pull algorithm to pull more data, but the pull could not yet be done since a
      previous call is still executing 
     <tr>
      <td>[[pullAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm that pulls data from the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①⑧">underlying source</a> 
     <tr>
      <td>[[pulling]] 
      <td class="non-normative">A boolean flag set to <emu-val>true</emu-val> while the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source①⑨">underlying source</a>’s
      pull algorithm is executing and the returned promise has not yet fulfilled, used to prevent reentrant calls 
     <tr>
      <td>[[queue]] 
      <td class="non-normative">A List representing the stream’s internal queue of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③⑤">chunks</a> 
     <tr>
      <td>[[queueTotalSize]] 
      <td class="non-normative">The total size of all the chunks stored in [[queue]] (see <a href="#queue-with-sizes">§ 6.2 Queue-with-sizes operations</a>) 
     <tr>
      <td>[[started]] 
      <td class="non-normative">A boolean flag indicating whether the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②⓪">underlying source</a> has finished starting 
     <tr>
      <td>[[strategyHWM]] 
      <td class="non-normative">A number supplied to the constructor as part of the stream’s <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy①">queuing strategy</a>,
      indicating the point at which the stream will apply <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure⑤">backpressure</a> to its <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②①">underlying source</a> 
     <tr>
      <td>[[strategySizeAlgorithm]] 
      <td class="non-normative">An algorithm to calculate the size of enqueued <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③⑥">chunks</a>, as part of the stream’s <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy②">queuing strategy</a> 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultController" data-dfn-type="constructor" data-export data-level="3.9.3" data-lt="ReadableStreamDefaultController()" id="rs-default-controller-constructor"><span class="secno">3.9.3. </span><span class="content">new ReadableStreamDefaultController()</span></h4>
   <div class="note" role="note"> The <code>ReadableStreamDefaultController</code> constructor cannot be used directly; <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class⑧">ReadableStreamDefaultController</a></code> instances are created automatically during <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②⑥">ReadableStream</a></code> construction. </div>
    <emu-alg>
  1. Throw a *TypeError*.
</emu-alg> 
   <h4 class="heading settled" data-level="3.9.4" id="rs-default-controller-prototype"><span class="secno">3.9.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class⑨">ReadableStreamDefaultController</a></code> prototype</span><a class="self-link" href="#rs-default-controller-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultController" data-dfn-type="attribute" data-export data-level="3.9.4.1" data-lt="desiredSize" id="rs-default-controller-desired-size"><span class="secno">3.9.4.1. </span><span class="content">get
desiredSize</span></h5>
   <div class="note" role="note"> The <code>desiredSize</code> getter returns the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue②">desired size
  to fill the controlled stream’s internal queue</a>. It can be negative, if the queue is over-full. An <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②②">underlying
  source</a> ought to use this information to determine when and how to apply <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure⑥">backpressure</a>. </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. Return ! ReadableStreamDefaultControllerGetDesiredSize(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultController" data-dfn-type="method" data-export data-level="3.9.4.2" data-lt="close()" id="rs-default-controller-close"><span class="secno">3.9.4.2. </span><span class="content">close()</span></h5>
   <div class="note" role="note"> The <code>close</code> method will close the controlled readable stream. <a data-link-type="dfn" href="#consumer" id="ref-for-consumer⑤">Consumers</a> will still be able to read
  any previously-enqueued <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③⑦">chunks</a> from the stream, but once those are read, the stream will become closed. </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(*this*) is *false*, throw a *TypeError* exception.
  1. Perform ! ReadableStreamDefaultControllerClose(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultController" data-dfn-type="method" data-export data-level="3.9.4.3" data-lt="enqueue(chunk)" id="rs-default-controller-enqueue"><span class="secno">3.9.4.3. </span><span class="content">enqueue(<var>chunk</var>)</span></h5>
   <div class="note" role="note"> The <code>enqueue</code> method will enqueue a given <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③⑧">chunk</a> in the controlled readable stream. </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(*this*) is *false*, throw a *TypeError* exception.
  1. Return ? ReadableStreamDefaultControllerEnqueue(*this*, _chunk_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamDefaultController" data-dfn-type="method" data-export data-level="3.9.4.4" data-lt="error(e)" id="rs-default-controller-error"><span class="secno">3.9.4.4. </span><span class="content">error(<var>e</var>)</span></h5>
   <div class="note" role="note"> The <code>error</code> method will error the readable stream, making all future interactions with it fail with the
  given error <code>e</code>. </div>
    <emu-alg>
  1. If ! IsReadableStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. Perform ! ReadableStreamDefaultControllerError(*this*, _e_).
</emu-alg> 
   <h4 class="heading settled" data-level="3.9.5" id="rs-default-controller-internal-methods"><span class="secno">3.9.5. </span><span class="content">Readable stream default controller internal methods</span><a class="self-link" href="#rs-default-controller-internal-methods"></a></h4>
   <p>The following are additional internal methods implemented by each <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class①⓪">ReadableStreamDefaultController</a></code> instance. The
readable stream implementation will polymorphically call to either these or their counterparts for BYOB controllers.</p>
   <h5 class="heading settled" data-level="3.9.5.1" id="rs-default-controller-private-cancel"><span class="secno">3.9.5.1. </span><span class="content"><a data-link-type="abstract-op" href="#abstract-opdef-cancelsteps" id="ref-for-abstract-opdef-cancelsteps①">[[CancelSteps]]</a>(<var>reason</var>)</span><a class="self-link" href="#rs-default-controller-private-cancel"></a></h5>
    <emu-alg>
  1. Perform ! ResetQueue(*this*).
  1. Let _result_ be the result of performing *this*.[[cancelAlgorithm]], passing _reason_.
  1. Perform ! ReadableStreamDefaultControllerClearAlgorithms(*this*).
  1. Return _result_.
</emu-alg> 
   <h5 class="heading settled" data-level="3.9.5.2" id="rs-default-controller-private-pull"><span class="secno">3.9.5.2. </span><span class="content"><a data-link-type="abstract-op" href="#abstract-opdef-pullsteps" id="ref-for-abstract-opdef-pullsteps①">[[PullSteps]]</a>( )</span><a class="self-link" href="#rs-default-controller-private-pull"></a></h5>
    <emu-alg>
  1. Let _stream_ be *this*.[[controlledReadableStream]].
  1. If *this*.[[queue]] is not empty,
    1. Let _chunk_ be ! DequeueValue(*this*).
    1. If *this*.[[closeRequested]] is *true* and *this*.[[queue]] is empty,
      1. Perform ! ReadableStreamDefaultControllerClearAlgorithms(*this*).
      1. Perform ! ReadableStreamClose(_stream_).
    1. Otherwise, perform ! ReadableStreamDefaultControllerCallPullIfNeeded(*this*).
    1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with⑨">a promise resolved with</a> ! ReadableStreamCreateReadResult(_chunk_, *false*,
       _stream_.[[reader]].[[forAuthorCode]]).
  1. Let _pendingPromise_ be ! ReadableStreamAddReadRequest(_stream_).
  1. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(*this*).
  1. Return _pendingPromise_.
</emu-alg> 
   <h3 class="heading settled" data-level="3.10" id="rs-default-controller-abstract-ops"><span class="secno">3.10. </span><span class="content">Readable stream default controller abstract operations</span><a class="self-link" href="#rs-default-controller-abstract-ops"></a></h3>
   <h4 aoid="IsReadableStreamDefaultController" class="heading settled" data-level="3.10.1" id="is-readable-stream-default-controller" nothrow><span class="secno">3.10.1. </span><span class="content">IsReadableStreamDefaultController ( <var>x</var> )</span><a class="self-link" href="#is-readable-stream-default-controller"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have a [[controlledReadableStream]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerCallPullIfNeeded" class="heading settled" data-level="3.10.2" id="readable-stream-default-controller-call-pull-if-needed" nothrow><span class="secno">3.10.2. </span><span class="content">ReadableStreamDefaultControllerCallPullIfNeeded ( <var>controller</var> )</span><a class="self-link" href="#readable-stream-default-controller-call-pull-if-needed"></a></h4>
    <emu-alg>
  1. Let _shouldPull_ be ! ReadableStreamDefaultControllerShouldCallPull(_controller_).
  1. If _shouldPull_ is *false*, return.
  1. If _controller_.[[pulling]] is *true*,
    1. Set _controller_.[[pullAgain]] to *true*.
    1. Return.
  1. Assert: _controller_.[[pullAgain]] is *false*.
  1. Set _controller_.[[pulling]] to *true*.
  1. Let _pullPromise_ be the result of performing _controller_.[[pullAlgorithm]].
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment①">Upon fulfillment</a> of _pullPromise_,
    1. Set _controller_.[[pulling]] to *false*.
    1. If _controller_.[[pullAgain]] is *true*,
      1. Set _controller_.[[pullAgain]] to *false*.
      1. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(_controller_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection②">Upon rejection</a> of _pullPromise_ with reason _e_,
    1. Perform ! ReadableStreamDefaultControllerError(_controller_, _e_).
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerShouldCallPull" class="heading settled" data-level="3.10.3" id="readable-stream-default-controller-should-call-pull" nothrow><span class="secno">3.10.3. </span><span class="content">ReadableStreamDefaultControllerShouldCallPull ( <var>controller</var> )</span><a class="self-link" href="#readable-stream-default-controller-should-call-pull"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableStream]].
  1. If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(_controller_) is *false*, return *false*.
  1. If _controller_.[[started]] is *false*, return *false*.
  1. If ! IsReadableStreamLocked(_stream_) is *true* and ! ReadableStreamGetNumReadRequests(_stream_) > *0*, return
     *true*.
  1. Let _desiredSize_ be ! ReadableStreamDefaultControllerGetDesiredSize(_controller_).
  1. Assert: _desiredSize_ is not *null*.
  1. If _desiredSize_ > *0*, return *true*.
  1. Return *false*.
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerClearAlgorithms" class="heading settled" data-export data-level="3.10.4" id="readable-stream-default-controller-clear-algorithms" nothrow><span class="secno">3.10.4. </span><span class="content">ReadableStreamDefaultControllerClearAlgorithms ( <var>controller</var> )</span><a class="self-link" href="#readable-stream-default-controller-clear-algorithms"></a></h4>
   <p>This abstract operation is called once the stream is closed or errored and the algorithms will not be executed any more.
By removing the algorithm references it permits the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②③">underlying source</a> object to be garbage collected even if the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②⑦">ReadableStream</a></code> itself is still referenced.</p>
   <p class="note" role="note">The results of this algorithm are not currently observable, but could become so if JavaScript eventually
adds <a href="https://github.com/tc39/proposal-weakrefs/">weak references</a>. But even without that factor,
implementations will likely want to include similar steps.</p>
    <emu-alg>
  1. Set _controller_.[[pullAlgorithm]] to *undefined*.
  1. Set _controller_.[[cancelAlgorithm]] to *undefined*.
  1. Set _controller_.[[strategySizeAlgorithm]] to *undefined*.
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerClose" class="heading settled" data-export data-level="3.10.5" id="readable-stream-default-controller-close" nothrow><span class="secno">3.10.5. </span><span class="content">ReadableStreamDefaultControllerClose ( <var>controller</var> )</span><a class="self-link" href="#readable-stream-default-controller-close"></a></h4>
   <p>This abstract operation can be called by other specifications that wish to close a readable stream, in the same way
a developer-created stream would be closed by its associated controller object. Specifications should <em>not</em> do
this to streams they did not create, and must ensure they have obeyed the preconditions (listed here as asserts).</p>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableStream]].
  1. Assert: ! ReadableStreamDefaultControllerCanCloseOrEnqueue(_controller_) is *true*.
  1. Set _controller_.[[closeRequested]] to *true*.
  1. If _controller_.[[queue]] is empty,
    1. Perform ! ReadableStreamDefaultControllerClearAlgorithms(_controller_).
    1. Perform ! ReadableStreamClose(_stream_).
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerEnqueue" class="heading settled" data-export data-level="3.10.6" id="readable-stream-default-controller-enqueue" throws><span class="secno">3.10.6. </span><span class="content">ReadableStreamDefaultControllerEnqueue ( <var>controller</var>, <var>chunk</var> )</span><a class="self-link" href="#readable-stream-default-controller-enqueue"></a></h4>
   <p>This abstract operation can be called by other specifications that wish to enqueue <a data-link-type="dfn" href="#chunk" id="ref-for-chunk③⑨">chunks</a> in a readable stream,
in the same way a developer would enqueue chunks using the stream’s associated controller object. Specifications should <em>not</em> do this to streams they did not create, and must ensure they have obeyed the preconditions (listed here as
asserts).</p>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableStream]].
  1. Assert: ! ReadableStreamDefaultControllerCanCloseOrEnqueue(_controller_) is *true*.
  1. If ! IsReadableStreamLocked(_stream_) is *true* and ! ReadableStreamGetNumReadRequests(_stream_) > *0*, perform
     ! ReadableStreamFulfillReadRequest(_stream_, _chunk_, *false*).
  1. Otherwise,
    1. Let _result_ be the result of performing _controller_.[[strategySizeAlgorithm]], passing in _chunk_, and
       interpreting the result as an ECMAScript completion value.
    1. If _result_ is an abrupt completion,
      1. Perform ! ReadableStreamDefaultControllerError(_controller_, _result_.[[Value]]).
      1. Return _result_.
    1. Let _chunkSize_ be _result_.[[Value]].
    1. Let _enqueueResult_ be EnqueueValueWithSize(_controller_, _chunk_, _chunkSize_).
    1. If _enqueueResult_ is an abrupt completion,
      1. Perform ! ReadableStreamDefaultControllerError(_controller_, _enqueueResult_.[[Value]]).
      1. Return _enqueueResult_.
  1. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(_controller_).
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerError" class="heading settled" data-export data-level="3.10.7" id="readable-stream-default-controller-error" nothrow><span class="secno">3.10.7. </span><span class="content">ReadableStreamDefaultControllerError ( <var>controller</var>, <var>e</var> )</span><a class="self-link" href="#readable-stream-default-controller-error"></a></h4>
   <p>This abstract operation can be called by other specifications that wish to move a readable stream to an errored state,
in the same way a developer would error a stream using its associated controller object. Specifications should <em>not</em> do this to streams they did not create.</p>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableStream]].
  1. If _stream_.[[state]] is not `"readable"`, return.
  1. Perform ! ResetQueue(_controller_).
  1. Perform ! ReadableStreamDefaultControllerClearAlgorithms(_controller_).
  1. Perform ! ReadableStreamError(_stream_, _e_).
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerGetDesiredSize" class="heading settled" data-export data-level="3.10.8" id="readable-stream-default-controller-get-desired-size" nothrow><span class="secno">3.10.8. </span><span class="content">ReadableStreamDefaultControllerGetDesiredSize ( <var>controller</var> )</span><a class="self-link" href="#readable-stream-default-controller-get-desired-size"></a></h4>
   <p>This abstract operation can be called by other specifications that wish to determine the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue③">desired size to fill this stream’s internal queue</a>, similar to how a developer would consult
the <code class="idl"><a data-link-type="idl" href="#rs-default-controller-desired-size" id="ref-for-rs-default-controller-desired-size①">desiredSize</a></code> property of the stream’s associated controller object.
Specifications should <em>not</em> use this on streams they did not create.</p>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableStream]].
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"errored"`, return *null*.
  1. If _state_ is `"closed"`, return *0*.
  1. Return _controller_.[[strategyHWM]] − _controller_.[[queueTotalSize]].
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerHasBackpressure" class="heading settled" data-level="3.10.9" id="rs-default-controller-has-backpressure" nothrow><span class="secno">3.10.9. </span><span class="content">ReadableStreamDefaultControllerHasBackpressure ( <var>controller</var> )</span><a class="self-link" href="#rs-default-controller-has-backpressure"></a></h4>
   <p>This abstract operation is used in the implementation of TransformStream.</p>
    <emu-alg>
  1. If ! ReadableStreamDefaultControllerShouldCallPull(_controller_) is *true*, return *false*.
  1. Otherwise, return *true*.
</emu-alg> 
   <h4 aoid="ReadableStreamDefaultControllerCanCloseOrEnqueue" class="heading settled" data-level="3.10.10" id="readable-stream-default-controller-can-close-or-enqueue" nothrow><span class="secno">3.10.10. </span><span class="content">ReadableStreamDefaultControllerCanCloseOrEnqueue ( <var>controller</var> )</span><a class="self-link" href="#readable-stream-default-controller-can-close-or-enqueue"></a></h4>
    <emu-alg>
  1. Let _state_ be _controller_.[[controlledReadableStream]].[[state]].
  1. If _controller_.[[closeRequested]] is *false* and _state_ is `"readable"`, return *true*.
  1. Otherwise, return *false*.
</emu-alg> 
   <div class="note" role="note"> The case where <var>stream</var>.[[closeRequested]] is <emu-val>false</emu-val>, but <var>stream</var>.[[state]] is
  not <code>"readable"</code>, happens when the stream is errored via <code class="idl"><a data-link-type="idl" href="#rs-default-controller-error" id="ref-for-rs-default-controller-error①">error(e)</a></code>, or
  when it is closed without its controller’s <code>close</code> method ever being called: e.g., if the stream was closed
  by a call to <code class="idl"><a data-link-type="idl" href="#rs-cancel" id="ref-for-rs-cancel③">cancel(reason)</a></code>. </div>
   <h4 aoid="SetUpReadableStreamDefaultController" class="heading settled" data-level="3.10.11" id="set-up-readable-stream-default-controller" throws><span class="secno">3.10.11. </span><span class="content">SetUpReadableStreamDefaultController(<var>stream</var>, <var>controller</var>, <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span><a class="self-link" href="#set-up-readable-stream-default-controller"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[readableStreamController]] is *undefined*.
  1. Set _controller_.[[controlledReadableStream]] to _stream_.
  1. Set _controller_.[[queue]] and _controller_.[[queueTotalSize]] to *undefined*, then perform !
     ResetQueue(_controller_).
  1. Set _controller_.[[started]], _controller_.[[closeRequested]], _controller_.[[pullAgain]], and
     _controller_.[[pulling]] to *false*.
  1. Set _controller_.[[strategySizeAlgorithm]] to _sizeAlgorithm_ and _controller_.[[strategyHWM]] to _highWaterMark_.
  1. Set _controller_.[[pullAlgorithm]] to _pullAlgorithm_.
  1. Set _controller_.[[cancelAlgorithm]] to _cancelAlgorithm_.
  1. Set _stream_.[[readableStreamController]] to _controller_.
  1. Let _startResult_ be the result of performing _startAlgorithm_. (This may throw an exception.)
  1. Let _startPromise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①⓪">a promise resolved with</a> _startResult_.
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment②">Upon fulfillment</a>  of _startPromise_,
    1. Set _controller_.[[started]] to *true*.
    1. Assert: _controller_.[[pulling]] is *false*.
    1. Assert: _controller_.[[pullAgain]] is *false*.
    1. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(_controller_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection③">Upon rejection</a> of _startPromise_ with reason _r_,
    1. Perform ! ReadableStreamDefaultControllerError(_controller_, _r_).
</emu-alg> 
   <h4 aoid="SetUpReadableStreamDefaultControllerFromUnderlyingSource" class="heading settled" data-level="3.10.12" id="set-up-readable-stream-default-controller-from-underlying-source" throws><span class="secno">3.10.12. </span><span class="content">SetUpReadableStreamDefaultControllerFromUnderlyingSource(<var>stream</var>, <var>underlyingSource</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span><a class="self-link" href="#set-up-readable-stream-default-controller-from-underlying-source"></a></h4>
    <emu-alg>
  1. Assert: _underlyingSource_ is not *undefined*.
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class①①">ReadableStreamDefaultController</a>`'s `prototype`
     property).
  1. Let _startAlgorithm_ be the following steps:
    1. Return ? InvokeOrNoop(_underlyingSource_, `"start"`, « _controller_ »).
  1. Let _pullAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_underlyingSource_, `"pull"`, *0*, « _controller_ »).
  1. Let _cancelAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_underlyingSource_, `"cancel"`, *1*, « »).
  1. Perform ? SetUpReadableStreamDefaultController(_stream_, _controller_, _startAlgorithm_, _pullAlgorithm_,
     _cancelAlgorithm_, _highWaterMark_, _sizeAlgorithm_).
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="3.11" data-lt="ReadableByteStreamController" id="rbs-controller-class"><span class="secno">3.11. </span><span class="content">Class <code>ReadableByteStreamController</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class④">ReadableByteStreamController</a></code> class has methods that allow control of a <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②⑧">ReadableStream</a></code>'s state and <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues⑥">internal queue</a>. When constructing a <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class②⑨">ReadableStream</a></code>, the <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source②">underlying byte source</a> is given a
corresponding <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class⑤">ReadableByteStreamController</a></code> instance to manipulate.</p>
   <h4 class="heading settled" data-level="3.11.1" id="rbs-controller-class-definition"><span class="secno">3.11.1. </span><span class="content">Class definition</span><a class="self-link" href="#rbs-controller-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class⑥">ReadableByteStreamController</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it
would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> ReadableByteStreamController <c- p>{</c->
  <a href="#rbs-controller-constructor" id="ref-for-rbs-controller-constructor">constructor</a><c- p>()</c-> <c- c1>// always throws</c->

  get <a href="#rbs-controller-byob-request" id="ref-for-rbs-controller-byob-request①">byobRequest</a><c- p>()</c->
  get <a href="#rbs-controller-desired-size" id="ref-for-rbs-controller-desired-size④">desiredSize</a><c- p>()</c->

  <a href="#rbs-controller-close" id="ref-for-rbs-controller-close">close</a><c- p>()</c->
  <a href="#rbs-controller-enqueue" id="ref-for-rbs-controller-enqueue">enqueue</a><c- p>(</c->chunk<c- p>)</c->
  <a href="#rbs-controller-error" id="ref-for-rbs-controller-error">error</a><c- p>(</c->e<c- p>)</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="3.11.2" id="rbs-controller-internal-slots"><span class="secno">3.11.2. </span><span class="content">Internal slots</span><a class="self-link" href="#rbs-controller-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class⑦">ReadableByteStreamController</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[autoAllocateChunkSize]] 
      <td class="non-normative">A positive integer, when the automatic buffer allocation feature is enabled. In that case,
      this value specifies the size of buffer to allocate. It is <emu-val>undefined</emu-val> otherwise. 
     <tr>
      <td>[[byobRequest]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#rs-byob-request-class" id="ref-for-rs-byob-request-class">ReadableStreamBYOBRequest</a></code> instance representing the current BYOB pull request,
      or <emu-val>undefined</emu-val> if there are no pending requests 
     <tr>
      <td>[[cancelAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm, taking one argument (the cancel reason), which communicates
      a requested cancelation to the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②④">underlying source</a> 
     <tr>
      <td>[[closeRequested]] 
      <td class="non-normative">A boolean flag indicating whether the stream has been closed by its <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source③">underlying byte
      source</a>, but still has <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④⓪">chunks</a> in its internal queue that have not yet been read 
     <tr>
      <td>[[controlledReadableByteStream]] 
      <td class="non-normative">The <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③⓪">ReadableStream</a></code> instance controlled 
     <tr>
      <td>[[pullAgain]] 
      <td class="non-normative">A boolean flag set to <emu-val>true</emu-val> if the stream’s mechanisms requested a call
      to the <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source④">underlying byte source</a>’s <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-pull" id="ref-for-dom-underlying-source-pull③">pull()</a></code> method to pull more data, but the pull could
      not yet be done since a previous call is still executing 
     <tr>
      <td>[[pullAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm that pulls data from the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②⑤">underlying source</a> 
     <tr>
      <td>[[pulling]] 
      <td class="non-normative">A boolean flag set to <emu-val>true</emu-val> while the <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source⑤">underlying byte source</a>’s <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-pull" id="ref-for-dom-underlying-source-pull④">pull()</a></code> method is executing and has not yet fulfilled, used to prevent reentrant calls 
     <tr>
      <td>[[pendingPullIntos]] 
      <td class="non-normative">A List of descriptors representing pending BYOB pull requests 
     <tr>
      <td>[[queue]] 
      <td class="non-normative">A List representing the stream’s internal queue of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④①">chunks</a> 
     <tr>
      <td>[[queueTotalSize]] 
      <td class="non-normative">The total size (in bytes) of all the chunks stored in [[queue]] 
     <tr>
      <td>[[started]] 
      <td class="non-normative">A boolean flag indicating whether the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②⑥">underlying source</a> has finished starting 
     <tr>
      <td>[[strategyHWM]] 
      <td class="non-normative">A number supplied to the constructor as part of the stream’s <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy③">queuing strategy</a>,
      indicating the point at which the stream will apply <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure⑦">backpressure</a> to its <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source⑥">underlying byte source</a> 
   </table>
   <div class="note" role="note">
    <p>Although <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class⑧">ReadableByteStreamController</a></code> instances have [[queue]] and [[queueTotalSize]] slots, we do not use
  most of the abstract operations in <a href="#queue-with-sizes">§ 6.2 Queue-with-sizes operations</a> on them, as the way in which we manipulate this queue is
  rather different than the others in the spec. Instead, we update the two slots together manually.</p>
    <p>This might be cleaned up in a future spec refactoring.</p>
   </div>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableByteStreamController" data-dfn-type="constructor" data-export data-level="3.11.3" data-lt="ReadableByteStreamController()" id="rbs-controller-constructor"><span class="secno">3.11.3. </span><span class="content">new
ReadableByteStreamController()</span></h4>
   <div class="note" role="note"> The <code>ReadableByteStreamController</code> constructor cannot be used directly; <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class⑨">ReadableByteStreamController</a></code> instances are created automatically during <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③①">ReadableStream</a></code> construction. </div>
    <emu-alg>
  1. Throw a *TypeError* exception.
</emu-alg> 
   <h4 class="heading settled" data-level="3.11.4" id="rbs-controller-prototype"><span class="secno">3.11.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class①⓪">ReadableByteStreamController</a></code> prototype</span><a class="self-link" href="#rbs-controller-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableByteStreamController" data-dfn-type="attribute" data-export data-level="3.11.4.1" data-lt="byobRequest" id="rbs-controller-byob-request"><span class="secno">3.11.4.1. </span><span class="content">get byobRequest</span></h5>
   <div class="note" role="note"> The <code>byobRequest</code> getter returns the current BYOB pull request. </div>
    <emu-alg>
  1. If ! IsReadableByteStreamController(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[byobRequest]] is *undefined* and *this*.[[pendingPullIntos]] is not empty,
    1. Let _firstDescriptor_ be the first element of *this*.[[pendingPullIntos]].
    1. Let _view_ be ! Construct(<a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-typedarray-objects" id="ref-for-sec-typedarray-objects②">%Uint8Array%</a>, « _firstDescriptor_.[[buffer]],
       _firstDescriptor_.[[byteOffset]] + _firstDescriptor_.[[bytesFilled]], _firstDescriptor_.[[byteLength]] −
       _firstDescriptor_.[[bytesFilled]] »).
    1. Let _byobRequest_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#rs-byob-request-class" id="ref-for-rs-byob-request-class①">ReadableStreamBYOBRequest</a>`'s `prototype`
      property).
    1. Perform ! SetUpReadableStreamBYOBRequest(_byobRequest_, *this*, _view_).
    1. Set *this*.[[byobRequest]] to _byobRequest_.
  1. Return *this*.[[byobRequest]].
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableByteStreamController" data-dfn-type="attribute" data-export data-level="3.11.4.2" data-lt="desiredSize" id="rbs-controller-desired-size"><span class="secno">3.11.4.2. </span><span class="content">get desiredSize</span></h5>
   <div class="note" role="note"> The <code>desiredSize</code> getter returns the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue④">desired size
  to fill the controlled stream’s internal queue</a>. It can be negative, if the queue is over-full. An <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②⑦">underlying
  source</a> ought to use this information to determine when and how to apply <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure⑧">backpressure</a>. </div>
    <emu-alg>
  1. If ! IsReadableByteStreamController(*this*) is *false*, throw a *TypeError* exception.
  1. Return ! ReadableByteStreamControllerGetDesiredSize(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableByteStreamController" data-dfn-type="method" data-export data-level="3.11.4.3" data-lt="close()" id="rbs-controller-close"><span class="secno">3.11.4.3. </span><span class="content">close()</span></h5>
   <div class="note" role="note"> The <code>close</code> method will close the controlled readable stream. <a data-link-type="dfn" href="#consumer" id="ref-for-consumer⑥">Consumers</a> will still be able to read
  any previously-enqueued <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④②">chunks</a> from the stream, but once those are read, the stream will become closed. </div>
    <emu-alg>
  1. If ! IsReadableByteStreamController(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[closeRequested]] is *true*, throw a *TypeError* exception.
  1. If *this*.[[controlledReadableByteStream]].[[state]] is not `"readable"`, throw a *TypeError* exception.
  1. Perform ? ReadableByteStreamControllerClose(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableByteStreamController" data-dfn-type="method" data-export data-level="3.11.4.4" data-lt="enqueue(chunk)" id="rbs-controller-enqueue"><span class="secno">3.11.4.4. </span><span class="content">enqueue(<var>chunk</var>)</span></h5>
   <div class="note" role="note"> The <code>enqueue</code> method will enqueue a given <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④③">chunk</a> in the controlled readable stream. </div>
    <emu-alg>
  1. If ! IsReadableByteStreamController(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[closeRequested]] is *true*, throw a *TypeError* exception.
  1. If *this*.[[controlledReadableByteStream]].[[state]] is not `"readable"`, throw a *TypeError* exception.
  1. If Type(_chunk_) is not Object, throw a *TypeError* exception.
  1. If _chunk_ does not have a [[ViewedArrayBuffer]] internal slot, throw a *TypeError* exception.
  1. If ! IsDetachedBuffer(_chunk_.[[ViewedArrayBuffer]]) is *true*, throw a *TypeError* exception.
  1. Return ! ReadableByteStreamControllerEnqueue(*this*, _chunk_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableByteStreamController" data-dfn-type="method" data-export data-level="3.11.4.5" data-lt="error(e)" id="rbs-controller-error"><span class="secno">3.11.4.5. </span><span class="content">error(<var>e</var>)</span></h5>
   <div class="note" role="note"> The <code>error</code> method will error the readable stream, making all future interactions with it fail with the
  given error <code>e</code>. </div>
    <emu-alg>
  1. If ! IsReadableByteStreamController(*this*) is *false*, throw a *TypeError* exception.
  1. Perform ! ReadableByteStreamControllerError(*this*, _e_).
</emu-alg> 
   <h4 class="heading settled" data-level="3.11.5" id="rbs-controller-internal-methods"><span class="secno">3.11.5. </span><span class="content">Readable stream BYOB controller internal methods</span><a class="self-link" href="#rbs-controller-internal-methods"></a></h4>
   <p>The following are additional internal methods implemented by each <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class①①">ReadableByteStreamController</a></code> instance. The
readable stream implementation will polymorphically call to either these or their counterparts for default controllers.</p>
   <h5 class="heading settled" data-level="3.11.5.1" id="rbs-controller-private-cancel"><span class="secno">3.11.5.1. </span><span class="content"><a data-link-type="abstract-op" href="#abstract-opdef-cancelsteps" id="ref-for-abstract-opdef-cancelsteps②">[[CancelSteps]]</a>(<var>reason</var>)</span><a class="self-link" href="#rbs-controller-private-cancel"></a></h5>
    <emu-alg>
  1. If *this*.[[pendingPullIntos]] is not empty,
    1. Let _firstDescriptor_ be the first element of *this*.[[pendingPullIntos]].
    1. Set _firstDescriptor_.[[bytesFilled]] to *0*.
  1. Perform ! ResetQueue(*this*).
  1. Let _result_ be the result of performing *this*.[[cancelAlgorithm]], passing in _reason_.
  1. Perform ! ReadableByteStreamControllerClearAlgorithms(*this*).
  1. Return _result_.
</emu-alg> 
   <h5 class="heading settled" data-level="3.11.5.2" id="rbs-controller-private-pull"><span class="secno">3.11.5.2. </span><span class="content"><a data-link-type="abstract-op" href="#abstract-opdef-pullsteps" id="ref-for-abstract-opdef-pullsteps②">[[PullSteps]]</a>( )</span><a class="self-link" href="#rbs-controller-private-pull"></a></h5>
    <emu-alg>
  1. Let _stream_ be *this*.[[controlledReadableByteStream]].
  1. Assert: ! ReadableStreamHasDefaultReader(_stream_) is *true*.
  1. If *this*.[[queueTotalSize]] > *0*,
    1. Assert: ! ReadableStreamGetNumReadRequests(_stream_) is *0*.
    1. Let _entry_ be the first element of *this*.[[queue]].
    1. Remove _entry_ from *this*.[[queue]], shifting all other elements downward (so that the second becomes the
       first, and so on).
    1. Set *this*.[[queueTotalSize]] to *this*.[[queueTotalSize]] − _entry_.[[byteLength]].
    1. Perform ! ReadableByteStreamControllerHandleQueueDrain(*this*).
    1. Let _view_ be ! Construct(<a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-typedarray-objects" id="ref-for-sec-typedarray-objects③">%Uint8Array%</a>, « _entry_.[[buffer]], _entry_.[[byteOffset]],
       _entry_.[[byteLength]] »).
    1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①①">a promise resolved with</a> ! ReadableStreamCreateReadResult(_view_, *false*,
       _stream_.[[reader]].[[forAuthorCode]]).
  1. Let _autoAllocateChunkSize_ be *this*.[[autoAllocateChunkSize]].
  1. If _autoAllocateChunkSize_ is not *undefined*,
    1. Let _buffer_ be Construct(%ArrayBuffer%, « _autoAllocateChunkSize_ »).
    1. If _buffer_ is an abrupt completion, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③①">a promise rejected with</a> _buffer_.[[Value]].
    1. Let _pullIntoDescriptor_ be Record {[[buffer]]: _buffer_.[[Value]], [[byteOffset]]: *0*, [[byteLength]]:
       _autoAllocateChunkSize_, [[bytesFilled]]: *0*, [[elementSize]]: *1*, [[ctor]]: <a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-typedarray-objects" id="ref-for-sec-typedarray-objects④">%Uint8Array%</a>,
       [[readerType]]: `"default"`}.
    1. Append _pullIntoDescriptor_ as the last element of *this*.[[pendingPullIntos]].
  1. Let _promise_ be ! ReadableStreamAddReadRequest(_stream_).
  1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(*this*).
  1. Return _promise_.
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="3.12" data-lt="ReadableStreamBYOBRequest" id="rs-byob-request-class"><span class="secno">3.12. </span><span class="content">Class <code>ReadableStreamBYOBRequest</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#rs-byob-request-class" id="ref-for-rs-byob-request-class②">ReadableStreamBYOBRequest</a></code> class represents a pull into request in a <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class①②">ReadableByteStreamController</a></code>.</p>
   <h4 class="heading settled" data-level="3.12.1" id="rs-byob-request-class-definition"><span class="secno">3.12.1. </span><span class="content">Class definition</span><a class="self-link" href="#rs-byob-request-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#rs-byob-request-class" id="ref-for-rs-byob-request-class③">ReadableStreamBYOBRequest</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it
would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> ReadableStreamBYOBRequest <c- p>{</c->
  <a href="#rs-byob-request-constructor" id="ref-for-rs-byob-request-constructor">constructor</a><c- p>(</c->controller<c- p>,</c-> view<c- p>)</c->

  get <a href="#rs-byob-request-view" id="ref-for-rs-byob-request-view">view</a><c- p>()</c->

  <a href="#rs-byob-request-respond" id="ref-for-rs-byob-request-respond">respond</a><c- p>(</c->bytesWritten<c- p>)</c->
  <a href="#rs-byob-request-respond-with-new-view" id="ref-for-rs-byob-request-respond-with-new-view">respondWithNewView</a><c- p>(</c->view<c- p>)</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="3.12.2" id="rs-byob-request-internal-slots"><span class="secno">3.12.2. </span><span class="content">Internal slots</span><a class="self-link" href="#rs-byob-request-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#rs-byob-request-class" id="ref-for-rs-byob-request-class④">ReadableStreamBYOBRequest</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[associatedReadableByteStreamController]] 
      <td class="non-normative">The parent <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class①③">ReadableByteStreamController</a></code> instance 
     <tr>
      <td>[[view]] 
      <td class="non-normative">A <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-typedarray-objects" id="ref-for-sec-typedarray-objects⑤">typed array</a> representing the destination region to which the controller can write
      generated data 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBRequest" data-dfn-type="constructor" data-export data-level="3.12.3" data-lt="ReadableStreamBYOBRequest(controller, view)" id="rs-byob-request-constructor"><span class="secno">3.12.3. </span><span class="content">new
ReadableStreamBYOBRequest()</span></h4>
    <emu-alg>
  1. Throw a *TypeError* exception.
</emu-alg> 
   <h4 class="heading settled" data-level="3.12.4" id="rs-byob-request-prototype"><span class="secno">3.12.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#rs-byob-request-class" id="ref-for-rs-byob-request-class⑤">ReadableStreamBYOBRequest</a></code> prototype</span><a class="self-link" href="#rs-byob-request-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBRequest" data-dfn-type="attribute" data-export data-level="3.12.4.1" data-lt="view" id="rs-byob-request-view"><span class="secno">3.12.4.1. </span><span class="content">get view</span></h5>
    <emu-alg>
  1. If ! IsReadableStreamBYOBRequest(*this*) is *false*, throw a *TypeError* exception.
  1. Return *this*.[[view]].
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBRequest" data-dfn-type="method" data-export data-level="3.12.4.2" data-lt="respond(bytesWritten)" id="rs-byob-request-respond"><span class="secno">3.12.4.2. </span><span class="content">respond(<var>bytesWritten</var>)</span></h5>
    <emu-alg>
  1. If ! IsReadableStreamBYOBRequest(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[associatedReadableByteStreamController]] is *undefined*, throw a *TypeError* exception.
  1. If ! IsDetachedBuffer(*this*.[[view]].[[ViewedArrayBuffer]]) is *true*, throw a *TypeError* exception.
  1. Return ? ReadableByteStreamControllerRespond(*this*.[[associatedReadableByteStreamController]], _bytesWritten_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ReadableStreamBYOBRequest" data-dfn-type="method" data-export data-level="3.12.4.3" data-lt="respondWithNewView(view)" id="rs-byob-request-respond-with-new-view"><span class="secno">3.12.4.3. </span><span class="content">respondWithNewView(<var>view</var>)</span></h5>
    <emu-alg>
  1. If ! IsReadableStreamBYOBRequest(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[associatedReadableByteStreamController]] is *undefined*, throw a *TypeError* exception.
  1. If Type(_view_) is not Object, throw a *TypeError* exception.
  1. If _view_ does not have a [[ViewedArrayBuffer]] internal slot, throw a *TypeError* exception.
  1. If ! IsDetachedBuffer(_view_.[[ViewedArrayBuffer]]) is *true*, throw a *TypeError* exception.
  1. Return ? ReadableByteStreamControllerRespondWithNewView(*this*.[[associatedReadableByteStreamController]], _view_).
</emu-alg> 
   <h3 class="heading settled" data-level="3.13" id="rbs-controller-abstract-ops"><span class="secno">3.13. </span><span class="content">Readable stream BYOB controller abstract operations</span><a class="self-link" href="#rbs-controller-abstract-ops"></a></h3>
   <h4 aoid="IsReadableStreamBYOBRequest" class="heading settled" data-level="3.13.1" id="is-readable-stream-byob-request" nothrow><span class="secno">3.13.1. </span><span class="content">IsReadableStreamBYOBRequest ( <var>x</var> )</span><a class="self-link" href="#is-readable-stream-byob-request"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have an [[associatedReadableByteStreamController]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="IsReadableByteStreamController" class="heading settled" data-level="3.13.2" id="is-readable-byte-stream-controller" nothrow><span class="secno">3.13.2. </span><span class="content">IsReadableByteStreamController
( <var>x</var> )</span><a class="self-link" href="#is-readable-byte-stream-controller"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have an [[controlledReadableByteStream]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerCallPullIfNeeded" class="heading settled" data-level="3.13.3" id="readable-byte-stream-controller-call-pull-if-needed" nothrow><span class="secno">3.13.3. </span><span class="content">ReadableByteStreamControllerCallPullIfNeeded ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-call-pull-if-needed"></a></h4>
    <emu-alg>
  1. Let _shouldPull_ be ! ReadableByteStreamControllerShouldCallPull(_controller_).
  1. If _shouldPull_ is *false*, return.
  1. If _controller_.[[pulling]] is *true*,
    1. Set _controller_.[[pullAgain]] to *true*.
    1. Return.
  1. Assert: _controller_.[[pullAgain]] is *false*.
  1. Set _controller_.[[pulling]] to *true*.
  1. Let _pullPromise_ be the result of performing _controller_.[[pullAlgorithm]].
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment③">Upon fulfillment</a> of _pullPromise_,
    1. Set _controller_.[[pulling]] to *false*.
    1. If _controller_.[[pullAgain]] is *true*,
      1. Set _controller_.[[pullAgain]] to *false*.
      1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection④">Upon rejection</a> of _pullPromise_ with reason _e_,
    1. Perform ! ReadableByteStreamControllerError(_controller_, _e_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerClearAlgorithms" class="heading settled" data-level="3.13.4" id="readable-byte-stream-controller-clear-algorithms" throws><span class="secno">3.13.4. </span><span class="content">ReadableByteStreamControllerClearAlgorithms ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-clear-algorithms"></a></h4>
   <p>This abstract operation is called once the stream is closed or errored and the algorithms will not be executed any more.
By removing the algorithm references it permits the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②⑧">underlying source</a> object to be garbage collected even if the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③②">ReadableStream</a></code> itself is still referenced.</p>
   <p class="note" role="note">The results of this algorithm are not currently observable, but could become so if JavaScript eventually
adds <a href="https://github.com/tc39/proposal-weakrefs/">weak references</a>. But even without that factor,
implementations will likely want to include similar steps.</p>
    <emu-alg>
  1. Set _controller_.[[pullAlgorithm]] to *undefined*.
  1. Set _controller_.[[cancelAlgorithm]] to *undefined*.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerClearPendingPullIntos" class="heading settled" data-level="3.13.5" id="readable-byte-stream-controller-clear-pending-pull-intos" nothrow><span class="secno">3.13.5. </span><span class="content">ReadableByteStreamControllerClearPendingPullIntos ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-clear-pending-pull-intos"></a></h4>
    <emu-alg>
  1. Perform ! ReadableByteStreamControllerInvalidateBYOBRequest(_controller_).
  1. Set _controller_.[[pendingPullIntos]] to a new empty List.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerClose" class="heading settled" data-level="3.13.6" id="readable-byte-stream-controller-close" throws><span class="secno">3.13.6. </span><span class="content">ReadableByteStreamControllerClose ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-close"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. Assert: _controller_.[[closeRequested]] is *false*.
  1. Assert: _stream_.[[state]] is `"readable"`.
  1. If _controller_.[[queueTotalSize]] > *0*,
    1. Set _controller_.[[closeRequested]] to *true*.
    1. Return.
  1. If _controller_.[[pendingPullIntos]] is not empty,
    1. Let _firstPendingPullInto_ be the first element of _controller_.[[pendingPullIntos]].
    1. If _firstPendingPullInto_.[[bytesFilled]] > *0*,
      1. Let _e_ be a new *TypeError* exception.
      1. Perform ! ReadableByteStreamControllerError(_controller_, _e_).
      1. Throw _e_.
  1. Perform ! ReadableByteStreamControllerClearAlgorithms(_controller_).
  1. Perform ! ReadableStreamClose(_stream_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerCommitPullIntoDescriptor" class="heading settled" data-level="3.13.7" id="readable-byte-stream-controller-commit-pull-into-descriptor" nothrow><span class="secno">3.13.7. </span><span class="content">ReadableByteStreamControllerCommitPullIntoDescriptor
( <var>stream</var>, <var>pullIntoDescriptor</var> )</span><a class="self-link" href="#readable-byte-stream-controller-commit-pull-into-descriptor"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[state]] is not `"errored"`.
  1. Let _done_ be *false*.
  1. If _stream_.[[state]] is `"closed"`,
    1. Assert: _pullIntoDescriptor_.[[bytesFilled]] is *0*.
    1. Set _done_ to *true*.
  1. Let _filledView_ be ! ReadableByteStreamControllerConvertPullIntoDescriptor(_pullIntoDescriptor_).
  1. If _pullIntoDescriptor_.[[readerType]] is `"default"`,
    1. Perform ! ReadableStreamFulfillReadRequest(_stream_, _filledView_, _done_).
  1. Otherwise,
    1. Assert: _pullIntoDescriptor_.[[readerType]] is `"byob"`.
    1. Perform ! ReadableStreamFulfillReadIntoRequest(_stream_, _filledView_, _done_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerConvertPullIntoDescriptor" class="heading settled" data-level="3.13.8" id="readable-byte-stream-controller-convert-pull-into-descriptor" nothrow><span class="secno">3.13.8. </span><span class="content">ReadableByteStreamControllerConvertPullIntoDescriptor ( <var>pullIntoDescriptor</var> )</span><a class="self-link" href="#readable-byte-stream-controller-convert-pull-into-descriptor"></a></h4>
    <emu-alg>
  1. Let _bytesFilled_ be _pullIntoDescriptor_.[[bytesFilled]].
  1. Let _elementSize_ be _pullIntoDescriptor_.[[elementSize]].
  1. Assert: _bytesFilled_ ≤ _pullIntoDescriptor_.[[byteLength]].
  1. Assert: _bytesFilled_ mod _elementSize_ is *0*.
  1. Return ! Construct(_pullIntoDescriptor_.[[ctor]], « _pullIntoDescriptor_.[[buffer]],
     _pullIntoDescriptor_.[[byteOffset]], _bytesFilled_ ÷ _elementSize_ »).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerEnqueue" class="heading settled" data-level="3.13.9" id="readable-byte-stream-controller-enqueue" nothrow><span class="secno">3.13.9. </span><span class="content">ReadableByteStreamControllerEnqueue ( <var>controller</var>, <var>chunk</var> )</span><a class="self-link" href="#readable-byte-stream-controller-enqueue"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. Assert: _controller_.[[closeRequested]] is *false*.
  1. Assert: _stream_.[[state]] is `"readable"`.
  1. Let _buffer_ be _chunk_.[[ViewedArrayBuffer]].
  1. Let _byteOffset_ be _chunk_.[[ByteOffset]].
  1. Let _byteLength_ be _chunk_.[[ByteLength]].
  1. Let _transferredBuffer_ be ! TransferArrayBuffer(_buffer_).
  1. If ! ReadableStreamHasDefaultReader(_stream_) is *true*
    1. If ! ReadableStreamGetNumReadRequests(_stream_) is *0*,
      1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(_controller_, _transferredBuffer_, _byteOffset_,
         _byteLength_).
    1. Otherwise,
      1. Assert: _controller_.[[queue]] is empty.
      1. Let _transferredView_ be ! Construct(<a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-typedarray-objects" id="ref-for-sec-typedarray-objects⑥">%Uint8Array%</a>, « _transferredBuffer_, _byteOffset_,
         _byteLength_ »).
      1. Perform ! ReadableStreamFulfillReadRequest(_stream_, _transferredView_, *false*).
  1. Otherwise, if ! ReadableStreamHasBYOBReader(_stream_) is *true*,
    1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(_controller_, _transferredBuffer_, _byteOffset_,
       _byteLength_).
    1. Perform ! ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(_controller_).
  1. Otherwise,
    1. Assert: ! IsReadableStreamLocked(_stream_) is *false*.
    1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(_controller_, _transferredBuffer_, _byteOffset_,
       _byteLength_).
  1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerEnqueueChunkToQueue" class="heading settled" data-level="3.13.10" id="readable-byte-stream-controller-enqueue-chunk-to-queue" nothrow><span class="secno">3.13.10. </span><span class="content">ReadableByteStreamControllerEnqueueChunkToQueue ( <var>controller</var>, <var>buffer</var>, <var>byteOffset</var>, <var>byteLength</var> )</span><a class="self-link" href="#readable-byte-stream-controller-enqueue-chunk-to-queue"></a></h4>
    <emu-alg>
  1. Append Record {[[buffer]]: _buffer_, [[byteOffset]]: _byteOffset_, [[byteLength]]: _byteLength_} as the last
     element of _controller_.[[queue]].
  1. Add _byteLength_ to _controller_.[[queueTotalSize]].
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerError" class="heading settled" data-level="3.13.11" id="readable-byte-stream-controller-error" nothrow><span class="secno">3.13.11. </span><span class="content">ReadableByteStreamControllerError ( <var>controller</var>, <var>e</var> )</span><a class="self-link" href="#readable-byte-stream-controller-error"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. If _stream_.[[state]] is not `"readable"`, return.
  1. Perform ! ReadableByteStreamControllerClearPendingPullIntos(_controller_).
  1. Perform ! ResetQueue(_controller_).
  1. Perform ! ReadableByteStreamControllerClearAlgorithms(_controller_).
  1. Perform ! ReadableStreamError(_stream_, _e_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerFillHeadPullIntoDescriptor" class="heading settled" data-level="3.13.12" id="readable-byte-stream-controller-fill-head-pull-into-descriptor" nothrow><span class="secno">3.13.12. </span><span class="content">ReadableByteStreamControllerFillHeadPullIntoDescriptor ( <var>controller</var>, <var>size</var>, <var>pullIntoDescriptor</var> )</span><a class="self-link" href="#readable-byte-stream-controller-fill-head-pull-into-descriptor"></a></h4>
    <emu-alg>
  1. Assert: either _controller_.[[pendingPullIntos]] is empty, or the first element of
     _controller_.[[pendingPullIntos]] is _pullIntoDescriptor_.
  1. Perform ! ReadableByteStreamControllerInvalidateBYOBRequest(_controller_).
  1. Set _pullIntoDescriptor_.[[bytesFilled]] to _pullIntoDescriptor_.[[bytesFilled]] + _size_.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerFillPullIntoDescriptorFromQueue" class="heading settled" data-level="3.13.13" id="readable-byte-stream-controller-fill-pull-into-descriptor-from-queue" nothrow><span class="secno">3.13.13. </span><span class="content">ReadableByteStreamControllerFillPullIntoDescriptorFromQueue ( <var>controller</var>, <var>pullIntoDescriptor</var> )</span><a class="self-link" href="#readable-byte-stream-controller-fill-pull-into-descriptor-from-queue"></a></h4>
    <emu-alg>
  1. Let _elementSize_ be _pullIntoDescriptor_.[[elementSize]].
  1. Let _currentAlignedBytes_ be _pullIntoDescriptor_.[[bytesFilled]] − (_pullIntoDescriptor_.[[bytesFilled]] mod
     _elementSize_).
  1. Let _maxBytesToCopy_ be min(_controller_.[[queueTotalSize]], _pullIntoDescriptor_.[[byteLength]] −
     _pullIntoDescriptor_.[[bytesFilled]]).
  1. Let _maxBytesFilled_ be _pullIntoDescriptor_.[[bytesFilled]] + _maxBytesToCopy_.
  1. Let _maxAlignedBytes_ be _maxBytesFilled_ − (_maxBytesFilled_ mod _elementSize_).
  1. Let _totalBytesToCopyRemaining_ be _maxBytesToCopy_.
  1. Let _ready_ be *false*.
  1. If _maxAlignedBytes_ > _currentAlignedBytes_,
    1. Set _totalBytesToCopyRemaining_ to _maxAlignedBytes_ − _pullIntoDescriptor_.[[bytesFilled]].
    1. Set _ready_ to *true*.
  1. Let _queue_ be _controller_.[[queue]].
  1. Repeat the following steps while _totalBytesToCopyRemaining_ > *0*,
    1. Let _headOfQueue_ be the first element of _queue_.
    1. Let _bytesToCopy_ be min(_totalBytesToCopyRemaining_, _headOfQueue_.[[byteLength]]).
    1. Let _destStart_ be _pullIntoDescriptor_.[[byteOffset]] + _pullIntoDescriptor_.[[bytesFilled]].
    1. Perform ! CopyDataBlockBytes(_pullIntoDescriptor_.[[buffer]].[[ArrayBufferData]], _destStart_,
       _headOfQueue_.[[buffer]].[[ArrayBufferData]], _headOfQueue_.[[byteOffset]], _bytesToCopy_).
    1. If _headOfQueue_.[[byteLength]] is _bytesToCopy_,
      1. Remove the first element of _queue_, shifting all other elements downward (so that the second becomes the
         first, and so on).
    1. Otherwise,
      1. Set _headOfQueue_.[[byteOffset]] to _headOfQueue_.[[byteOffset]] + _bytesToCopy_.
      1. Set _headOfQueue_.[[byteLength]] to _headOfQueue_.[[byteLength]] − _bytesToCopy_.
    1. Set _controller_.[[queueTotalSize]] to _controller_.[[queueTotalSize]] − _bytesToCopy_.
    1. Perform ! ReadableByteStreamControllerFillHeadPullIntoDescriptor(_controller_, _bytesToCopy_,
       _pullIntoDescriptor_).
    1. Set _totalBytesToCopyRemaining_ to _totalBytesToCopyRemaining_ − _bytesToCopy_.
  1. If _ready_ is *false*,
    1. Assert: _controller_.[[queueTotalSize]] is *0*.
    1. Assert: _pullIntoDescriptor_.[[bytesFilled]] > *0*.
    1. Assert: _pullIntoDescriptor_.[[bytesFilled]] &lt; _pullIntoDescriptor_.[[elementSize]].
  1. Return _ready_.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerGetDesiredSize" class="heading settled" data-level="3.13.14" id="readable-byte-stream-controller-get-desired-size" nothrow><span class="secno">3.13.14. </span><span class="content">ReadableByteStreamControllerGetDesiredSize ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-get-desired-size"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"errored"`, return *null*.
  1. If _state_ is `"closed"`, return *0*.
  1. Return _controller_.[[strategyHWM]] − _controller_.[[queueTotalSize]].
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerHandleQueueDrain" class="heading settled" data-level="3.13.15" id="readable-byte-stream-controller-handle-queue-drain" nothrow><span class="secno">3.13.15. </span><span class="content">ReadableByteStreamControllerHandleQueueDrain ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-handle-queue-drain"></a></h4>
    <emu-alg>
  1. Assert: _controller_.[[controlledReadableByteStream]].[[state]] is `"readable"`.
  1. If _controller_.[[queueTotalSize]] is *0* and _controller_.[[closeRequested]] is *true*,
    1. Perform ! ReadableByteStreamControllerClearAlgorithms(_controller_).
    1. Perform ! ReadableStreamClose(_controller_.[[controlledReadableByteStream]]).
  1. Otherwise,
    1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerInvalidateBYOBRequest" class="heading settled" data-level="3.13.16" id="readable-byte-stream-controller-invalidate-byob-request" nothrow><span class="secno">3.13.16. </span><span class="content">ReadableByteStreamControllerInvalidateBYOBRequest ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-invalidate-byob-request"></a></h4>
    <emu-alg>
  1. If _controller_.[[byobRequest]] is *undefined*, return.
  1. Set _controller_.[[byobRequest]].[[associatedReadableByteStreamController]] to *undefined*.
  1. Set _controller_.[[byobRequest]].[[view]] to *undefined*.
  1. Set _controller_.[[byobRequest]] to *undefined*.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue" class="heading settled" data-level="3.13.17" id="readable-byte-stream-controller-process-pull-into-descriptors-using-queue" nothrow><span class="secno">3.13.17. </span><span class="content">ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-process-pull-into-descriptors-using-queue"></a></h4>
    <emu-alg>
  1. Assert: _controller_.[[closeRequested]] is *false*.
  1. Repeat the following steps while _controller_.[[pendingPullIntos]] is not empty,
    1. If _controller_.[[queueTotalSize]] is *0*, return.
    1. Let _pullIntoDescriptor_ be the first element of _controller_.[[pendingPullIntos]].
    1. If ! ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(_controller_, _pullIntoDescriptor_) is *true*,
      1. Perform ! ReadableByteStreamControllerShiftPendingPullInto(_controller_).
      1. Perform ! ReadableByteStreamControllerCommitPullIntoDescriptor(_controller_.[[controlledReadableByteStream]],
         _pullIntoDescriptor_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerPullInto" class="heading settled" data-level="3.13.18" id="readable-byte-stream-controller-pull-into" nothrow><span class="secno">3.13.18. </span><span class="content">ReadableByteStreamControllerPullInto ( <var>controller</var>, <var>view</var> )</span><a class="self-link" href="#readable-byte-stream-controller-pull-into"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. Let _elementSize_ be 1.
  1. Let _ctor_ be %DataView%.
  1. If _view_ has a [[TypedArrayName]] internal slot (i.e., it is not a `<a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-dataview-objects" id="ref-for-sec-dataview-objects">DataView</a>`),
    1. Set _elementSize_ to the element size specified in <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#table-49" id="ref-for-table-49">the typed array constructors table</a> for
       _view_.[[TypedArrayName]].
    1. Set _ctor_ to the constructor specified in <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#table-49" id="ref-for-table-49①">the typed array constructors table</a> for
       _view_.[[TypedArrayName]].
  1. Let _byteOffset_ be _view_.[[ByteOffset]].
  1. Let _byteLength_ be _view_.[[ByteLength]].
  1. Let _buffer_ be ! TransferArrayBuffer(_view_.[[ViewedArrayBuffer]]).
  1. Let _pullIntoDescriptor_ be Record {[[buffer]]: _buffer_, [[byteOffset]]: _byteOffset_,
     [[byteLength]]: _byteLength_, [[bytesFilled]]: *0*, [[elementSize]]: _elementSize_,
     [[ctor]]: _ctor_, [[readerType]]: `"byob"`}.
  1. If _controller_.[[pendingPullIntos]] is not empty,
    1. Append _pullIntoDescriptor_ as the last element of _controller_.[[pendingPullIntos]].
    1. Return ! ReadableStreamAddReadIntoRequest(_stream_).
  1. If _stream_.[[state]] is `"closed"`,
    1. Let _emptyView_ be ! Construct(_ctor_, « _pullIntoDescriptor_.[[buffer]], _pullIntoDescriptor_.[[byteOffset]], *0* »).
    1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①②">a promise resolved with</a> ! ReadableStreamCreateReadResult(_emptyView_, *true*,
       _stream_.[[reader]].[[forAuthorCode]]).
  1. If _controller_.[[queueTotalSize]] > *0*,
    1. If ! ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(_controller_, _pullIntoDescriptor_) is *true*,
      1. Let _filledView_ be ! ReadableByteStreamControllerConvertPullIntoDescriptor(_pullIntoDescriptor_).
      1. Perform ! ReadableByteStreamControllerHandleQueueDrain(_controller_).
      1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①③">a promise resolved with</a> ! ReadableStreamCreateReadResult(_filledView_, *false*,
         _stream_.[[reader]].[[forAuthorCode]]).
    1. If _controller_.[[closeRequested]] is *true*,
      1. Let _e_ be a *TypeError* exception.
      1. Perform ! ReadableByteStreamControllerError(_controller_, _e_).
      1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③②">a promise rejected with</a> _e_.
  1. Append _pullIntoDescriptor_ as the last element of _controller_.[[pendingPullIntos]].
  1. Let _promise_ be ! ReadableStreamAddReadIntoRequest(_stream_).
  1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
  1. Return _promise_.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerRespond" class="heading settled" data-level="3.13.19" id="readable-byte-stream-controller-respond" throws><span class="secno">3.13.19. </span><span class="content">ReadableByteStreamControllerRespond ( <var>controller</var>, <var>bytesWritten</var> )</span><a class="self-link" href="#readable-byte-stream-controller-respond"></a></h4>
    <emu-alg>
  1. Let _bytesWritten_ be ? ToNumber(_bytesWritten_).
  1. If ! IsFiniteNonNegativeNumber(_bytesWritten_) is *false*,
    1. Throw a *RangeError* exception.
  1. Assert: _controller_.[[pendingPullIntos]] is not empty.
  1. Perform ? ReadableByteStreamControllerRespondInternal(_controller_, _bytesWritten_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerRespondInClosedState" class="heading settled" data-level="3.13.20" id="readable-byte-stream-controller-respond-in-closed-state" nothrow><span class="secno">3.13.20. </span><span class="content">ReadableByteStreamControllerRespondInClosedState ( <var>controller</var>, <var>firstDescriptor</var> )</span><a class="self-link" href="#readable-byte-stream-controller-respond-in-closed-state"></a></h4>
    <emu-alg>
  1. Set _firstDescriptor_.[[buffer]] to ! TransferArrayBuffer(_firstDescriptor_.[[buffer]]).
  1. Assert: _firstDescriptor_.[[bytesFilled]] is *0*.
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. If ! ReadableStreamHasBYOBReader(_stream_) is *true*,
    1. Repeat the following steps while ! ReadableStreamGetNumReadIntoRequests(_stream_) > *0*,
      1. Let _pullIntoDescriptor_ be ! ReadableByteStreamControllerShiftPendingPullInto(_controller_).
      1. Perform ! ReadableByteStreamControllerCommitPullIntoDescriptor(_stream_, _pullIntoDescriptor_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerRespondInReadableState" class="heading settled" data-level="3.13.21" id="readable-byte-stream-controller-respond-in-readable-state" throws><span class="secno">3.13.21. </span><span class="content">ReadableByteStreamControllerRespondInReadableState ( <var>controller</var>, <var>bytesWritten</var>, <var>pullIntoDescriptor</var> )</span><a class="self-link" href="#readable-byte-stream-controller-respond-in-readable-state"></a></h4>
    <emu-alg>
  1. If _pullIntoDescriptor_.[[bytesFilled]] + _bytesWritten_ > _pullIntoDescriptor_.[[byteLength]], throw a
     *RangeError* exception.
  1. Perform ! ReadableByteStreamControllerFillHeadPullIntoDescriptor(_controller_, _bytesWritten_,
     _pullIntoDescriptor_).
  1. If _pullIntoDescriptor_.[[bytesFilled]] &lt; _pullIntoDescriptor_.[[elementSize]], return.
  1. Perform ! ReadableByteStreamControllerShiftPendingPullInto(_controller_).
  1. Let _remainderSize_ be _pullIntoDescriptor_.[[bytesFilled]] mod _pullIntoDescriptor_.[[elementSize]].
  1. If _remainderSize_ > *0*,
    1. Let _end_ be _pullIntoDescriptor_.[[byteOffset]] + _pullIntoDescriptor_.[[bytesFilled]].
    1. Let _remainder_ be ? CloneArrayBuffer(_pullIntoDescriptor_.[[buffer]], _end_ − _remainderSize_, _remainderSize_,
       %ArrayBuffer%).
    1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(_controller_, _remainder_, *0*,
       _remainder_.[[ByteLength]]).
  1. Set _pullIntoDescriptor_.[[buffer]] to ! TransferArrayBuffer(_pullIntoDescriptor_.[[buffer]]).
  1. Set _pullIntoDescriptor_.[[bytesFilled]] to _pullIntoDescriptor_.[[bytesFilled]] − _remainderSize_.
  1. Perform ! ReadableByteStreamControllerCommitPullIntoDescriptor(_controller_.[[controlledReadableByteStream]],
     _pullIntoDescriptor_).
  1. Perform ! ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(_controller_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerRespondInternal" class="heading settled" data-level="3.13.22" id="readable-byte-stream-controller-respond-internal" throws><span class="secno">3.13.22. </span><span class="content">ReadableByteStreamControllerRespondInternal ( <var>controller</var>, <var>bytesWritten</var> )</span><a class="self-link" href="#readable-byte-stream-controller-respond-internal"></a></h4>
    <emu-alg>
  1. Let _firstDescriptor_ be the first element of _controller_.[[pendingPullIntos]].
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. If _stream_.[[state]] is `"closed"`,
    1. If _bytesWritten_ is not *0*, throw a *TypeError* exception.
    1. Perform ! ReadableByteStreamControllerRespondInClosedState(_controller_, _firstDescriptor_).
  1. Otherwise,
    1. Assert: _stream_.[[state]] is `"readable"`.
    1. Perform ? ReadableByteStreamControllerRespondInReadableState(_controller_, _bytesWritten_, _firstDescriptor_).
  1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerRespondWithNewView" class="heading settled" data-level="3.13.23" id="readable-byte-stream-controller-respond-with-new-view" throws><span class="secno">3.13.23. </span><span class="content">ReadableByteStreamControllerRespondWithNewView ( <var>controller</var>, <var>view</var> )</span><a class="self-link" href="#readable-byte-stream-controller-respond-with-new-view"></a></h4>
    <emu-alg>
  1. Assert: _controller_.[[pendingPullIntos]] is not empty.
  1. Let _firstDescriptor_ be the first element of _controller_.[[pendingPullIntos]].
  1. If _firstDescriptor_.[[byteOffset]] + _firstDescriptor_.[[bytesFilled]] is not _view_.[[ByteOffset]], throw a
     *RangeError* exception.
  1. If _firstDescriptor_.[[byteLength]] is not _view_.[[ByteLength]], throw a *RangeError* exception.
  1. Set _firstDescriptor_.[[buffer]] to _view_.[[ViewedArrayBuffer]].
  1. Perform ? ReadableByteStreamControllerRespondInternal(_controller_, _view_.[[ByteLength]]).
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerShiftPendingPullInto" class="heading settled" data-level="3.13.24" id="readable-byte-stream-controller-shift-pending-pull-into" nothrow><span class="secno">3.13.24. </span><span class="content">ReadableByteStreamControllerShiftPendingPullInto ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-shift-pending-pull-into"></a></h4>
    <emu-alg>
  1. Let _descriptor_ be the first element of _controller_.[[pendingPullIntos]].
  1. Remove _descriptor_ from _controller_.[[pendingPullIntos]], shifting all other elements downward (so that the
     second becomes the first, and so on).
  1. Perform ! ReadableByteStreamControllerInvalidateBYOBRequest(_controller_).
  1. Return _descriptor_.
</emu-alg> 
   <h4 aoid="ReadableByteStreamControllerShouldCallPull" class="heading settled" data-level="3.13.25" id="readable-byte-stream-controller-should-call-pull" nothrow><span class="secno">3.13.25. </span><span class="content">ReadableByteStreamControllerShouldCallPull ( <var>controller</var> )</span><a class="self-link" href="#readable-byte-stream-controller-should-call-pull"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
  1. If _stream_.[[state]] is not `"readable"`, return *false*.
  1. If _controller_.[[closeRequested]] is *true*, return *false*.
  1. If _controller_.[[started]] is *false*, return *false*.
  1. If ! ReadableStreamHasDefaultReader(_stream_) is *true* and ! ReadableStreamGetNumReadRequests(_stream_) > *0*,
     return *true*.
  1. If ! ReadableStreamHasBYOBReader(_stream_) is *true* and ! ReadableStreamGetNumReadIntoRequests(_stream_) > *0*,
     return *true*.
  1. Let _desiredSize_ be  ! ReadableByteStreamControllerGetDesiredSize(_controller_).
  1. Assert: _desiredSize_ is not *null*.
  1. If _desiredSize_ > *0*, return *true*.
  1. Return *false*.
</emu-alg> 
   <h4 aoid="SetUpReadableByteStreamController" class="heading settled" data-level="3.13.26" id="set-up-readable-byte-stream-controller" throws><span class="secno">3.13.26. </span><span class="content">SetUpReadableByteStreamController ( <var>stream</var>, <var>controller</var>, <var>startAlgorithm</var>, <var>pullAlgorithm</var>, <var>cancelAlgorithm</var>, <var>highWaterMark</var>, <var>autoAllocateChunkSize</var> )</span><a class="self-link" href="#set-up-readable-byte-stream-controller"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[readableStreamController]] is *undefined*.
  1. If _autoAllocateChunkSize_ is not *undefined*,
    1. Assert: ! IsInteger(_autoAllocateChunkSize_) is *true*.
    1. Assert: _autoAllocateChunkSize_ is positive.
  1. Set _controller_.[[controlledReadableByteStream]] to _stream_.
  1. Set _controller_.[[pullAgain]] and _controller_.[[pulling]] to *false*.
  1. Set _controller_.[[byobRequest]] to *undefined*.
  1. Perform ! ResetQueue(_controller_).
  1. Set _controller_.[[closeRequested]] and _controller_.[[started]] to *false*.
  1. Set _controller_.[[strategyHWM]] to ? ValidateAndNormalizeHighWaterMark(_highWaterMark_).
  1. Set _controller_.[[pullAlgorithm]] to _pullAlgorithm_.
  1. Set _controller_.[[cancelAlgorithm]] to _cancelAlgorithm_.
  1. Set _controller_.[[autoAllocateChunkSize]] to _autoAllocateChunkSize_.
  1. Set _controller_.[[pendingPullIntos]] to a new empty List.
  1. Set _stream_.[[readableStreamController]] to _controller_.
  1. Let _startResult_ be the result of performing _startAlgorithm_.
  1. Let _startPromise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①④">a promise resolved with</a> _startResult_.
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment④">Upon fulfillment</a>  of _startPromise_,
    1. Set _controller_.[[started]] to *true*.
    1. Assert: _controller_.[[pulling]] is *false*.
    1. Assert: _controller_.[[pullAgain]] is *false*.
    1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection⑤">Upon rejection</a> of _startPromise_ with reason _r_,
    1. Perform ! ReadableByteStreamControllerError(_controller_, _r_).
</emu-alg> 
   <h4 aoid="SetUpReadableByteStreamControllerFromUnderlyingSource" class="heading settled" data-level="3.13.27" id="set-up-readable-byte-stream-controller-from-underlying-source" throws><span class="secno">3.13.27. </span><span class="content">SetUpReadableByteStreamControllerFromUnderlyingSource ( <var>stream</var>, <var>underlyingByteSource</var>, <var>highWaterMark</var> )</span><a class="self-link" href="#set-up-readable-byte-stream-controller-from-underlying-source"></a></h4>
    <emu-alg>
  1. Assert: _underlyingByteSource_ is not *undefined*.
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class①④">ReadableByteStreamController</a>`'s `prototype`
     property).
  1. Let _startAlgorithm_ be the following steps:
    1. Return ? InvokeOrNoop(_underlyingByteSource_, `"start"`, « _controller_ »).
  1. Let _pullAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_underlyingByteSource_, `"pull"`, *0*, « _controller_
     »).
  1. Let _cancelAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_underlyingByteSource_, `"cancel"`, *1*, « »).
  1. Let _autoAllocateChunkSize_ be ? GetV(_underlyingByteSource_, `"autoAllocateChunkSize"`).
  1. If _autoAllocateChunkSize_ is not *undefined*,
    1. Set _autoAllocateChunkSize_ to ? ToNumber(_autoAllocateChunkSize_).
    1. If ! IsInteger(_autoAllocateChunkSize_) is *false*, or if _autoAllocateChunkSize_ ≤ *0*, throw a *RangeError*
       exception.
  1. Perform ? SetUpReadableByteStreamController(_stream_, _controller_, _startAlgorithm_, _pullAlgorithm_,
     _cancelAlgorithm_, _highWaterMark_, _autoAllocateChunkSize_).
</emu-alg> 
   <h4 aoid="SetUpReadableStreamBYOBRequest" class="heading settled" data-level="3.13.28" id="set-up-readable-stream-byob-request" nothrow><span class="secno">3.13.28. </span><span class="content">SetUpReadableStreamBYOBRequest ( <var>request</var>, <var>controller</var>, <var>view</var> )</span><a class="self-link" href="#set-up-readable-stream-byob-request"></a></h4>
    <emu-alg>
  1. Assert: ! IsReadableByteStreamController(_controller_) is *true*.
  1. Assert: Type(_view_) is Object.
  1. Assert: _view_ has a [[ViewedArrayBuffer]] internal slot.
  1. Assert: ! IsDetachedBuffer(_view_.[[ViewedArrayBuffer]]) is *false*.
  1. Set _request_.[[associatedReadableByteStreamController]] to _controller_.
  1. Set _request_.[[view]] to _view_.
</emu-alg> 
   <h2 class="heading settled" data-level="4" id="ws"><span class="secno">4. </span><span class="content">Writable streams</span><a class="self-link" href="#ws"></a></h2>
   <h3 class="heading settled" data-level="4.1" id="ws-intro"><span class="secno">4.1. </span><span class="content">Using writable streams</span><a class="self-link" href="#ws-intro"></a></h3>
   <div class="example" id="example-basic-pipe-to-2">
    <a class="self-link" href="#example-basic-pipe-to-2"></a> The usual way to write to a writable stream is to simply <a data-link-type="dfn" href="#piping" id="ref-for-piping⑧">pipe</a> a <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①②">readable stream</a> to it.
  This ensures that <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure⑨">backpressure</a> is respected, so that if the writable stream’s <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink④">underlying sink</a> is not
  able to accept data as fast as the readable stream can produce it, the readable stream is informed of this and has a
  chance to slow down its data production. 
<pre><code class="lang-javascript highlight">readableStream<c- p>.</c->pipeTo<c- p>(</c->writableStream<c- p>)</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"All data successfully written!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Something went wrong!"</c-><c- p>,</c-> e<c- p>));</c->
</code></pre>
   </div>
   <div class="example" id="example-manual-write-batch">
    <a class="self-link" href="#example-manual-write-batch"></a> You can also write directly to writable streams by acquiring a <a data-link-type="dfn" href="#writer" id="ref-for-writer①">writer</a> and using its <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write">write()</a></code> and <code class="idl"><a data-link-type="idl" href="#default-writer-close" id="ref-for-default-writer-close">close()</a></code> methods. Since writable streams
  queue any incoming writes, and take care internally to forward them to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink⑤">underlying sink</a> in sequence, you can
  indiscriminately write to a writable stream without much ceremony: 
<pre><code class="lang-javascript highlight"><c- a>function</c-> writeArrayToStream<c- p>(</c->array<c- p>,</c-> writableStream<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> writer <c- o>=</c-> writableStream<c- p>.</c->getWriter<c- p>();</c->
  array<c- p>.</c->forEach<c- p>(</c->chunk <c- p>=></c-> writer<c- p>.</c->write<c- p>(</c->chunk<c- p>).</c-><c- k>catch</c-><c- p>(()</c-> <c- p>=></c-> <c- p>{}));</c->

  <c- k>return</c-> writer<c- p>.</c->close<c- p>();</c->
<c- p>}</c->

writeArrayToStream<c- p>([</c-><c- mi>1</c-><c- p>,</c-> <c- mi>2</c-><c- p>,</c-> <c- mi>3</c-><c- p>,</c-> <c- mi>4</c-><c- p>,</c-> <c- mi>5</c-><c- p>],</c-> writableStream<c- p>)</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"All done!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Error with the stream: "</c-> <c- o>+</c-> e<c- p>));</c->
</code></pre>
    <p>Note how we use <code>.catch(() => {})</code> to suppress any rejections from the <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write①">write()</a></code> method; we’ll be notified of any fatal errors via a rejection of the <code class="idl"><a data-link-type="idl" href="#default-writer-close" id="ref-for-default-writer-close①">close()</a></code> method, and leaving them un-caught would cause potential <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/indices.html#event-unhandledrejection" id="ref-for-event-unhandledrejection">unhandledrejection</a></code> events and console warnings.</p>
   </div>
   <div class="example" id="example-manual-write-with-error-handling">
    <a class="self-link" href="#example-manual-write-with-error-handling"></a> In the previous example we only paid attention to the success or failure of the entire stream, by looking at the
  promise returned by the writer’s <code class="idl"><a data-link-type="idl" href="#default-writer-close" id="ref-for-default-writer-close②">close()</a></code> method. That promise will reject if anything
  goes wrong with the stream—initializing it, writing to it, or closing it. And it will fulfill once the stream is
  successfully closed. Often this is all you care about. 
    <p>However, if you care about the success of writing a specific <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④④">chunk</a>, you can use the promise returned by the
  writer’s <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write②">write()</a></code> method:</p>
<pre><code class="lang-javascript highlight">writer<c- p>.</c->write<c- p>(</c-><c- u>"i am a chunk of data"</c-><c- p>)</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"chunk successfully written!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c->e<c- p>));</c->
</code></pre>
    <p>What "success" means is up to a given stream instance (or more precisely, its <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink⑥">underlying sink</a>) to decide. For
  example, for a file stream it could simply mean that the OS has accepted the write, and not necessarily that the
  chunk has been flushed to disk. Some streams might not be able to give such a signal at all, in which case the
  returned promise will fulfill immediately.</p>
   </div>
   <div class="example" id="example-manual-write-with-backpressure">
    <a class="self-link" href="#example-manual-write-with-backpressure"></a> The <code class="idl"><a data-link-type="idl" href="#default-writer-desired-size" id="ref-for-default-writer-desired-size①">desiredSize</a></code> and <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready">ready</a></code> properties of <a data-link-type="dfn" href="#writer" id="ref-for-writer②">writable
  stream writers</a> allow <a data-link-type="dfn" href="#producer" id="ref-for-producer①">producers</a> to more precisely respond to flow control signals from the stream, to keep
  memory usage below the stream’s specified <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark②">high water mark</a>. The following example writes an infinite sequence of
  random bytes to a stream, using <code class="idl"><a data-link-type="idl" href="#default-writer-desired-size" id="ref-for-default-writer-desired-size②">desiredSize</a></code> to determine how many bytes to generate at
  a given time, and using <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready①">ready</a></code> to wait for the <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①⓪">backpressure</a> to subside. 
<pre><code class="lang-javascript highlight">async <c- a>function</c-> writeRandomBytesForever<c- p>(</c->writableStream<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> writer <c- o>=</c-> writableStream<c- p>.</c->getWriter<c- p>();</c->

  <c- k>while</c-> <c- p>(</c-><c- kc>true</c-><c- p>)</c-> <c- p>{</c->
    await writer<c- p>.</c->ready<c- p>;</c->

    <c- kr>const</c-> bytes <c- o>=</c-> <c- k>new</c-> Uint8Array<c- p>(</c->writer<c- p>.</c->desiredSize<c- p>);</c->
    crypto<c- p>.</c->getRandomValues<c- p>(</c->bytes<c- p>);</c->

    <c- c1>// Purposefully don’t await; awaiting writer.ready is enough.</c->
    writer<c- p>.</c->write<c- p>(</c->bytes<c- p>).</c-><c- k>catch</c-><c- p>(()</c-> <c- p>=></c-> <c- p>{});</c->
  <c- p>}</c->
<c- p>}</c->

writeRandomBytesForever<c- p>(</c->myWritableStream<c- p>).</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Something broke"</c-><c- p>,</c-> e<c- p>));</c->
</code></pre>
    <p>Note how we don’t <code>await</code> the promise returned by <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write③">write()</a></code>; this would be
  redundant with <code>await</code>ing the <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready②">ready</a></code> promise. Additionally, similar to <a href="#example-manual-write-batch">a previous example</a>, we use the <code>.catch(() => {})</code> pattern on the
  promises returned by <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write④">write()</a></code>; in this case we’ll be notified about any failures <code>await</code>ing the <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready③">ready</a></code> promise.</p>
   </div>
   <div class="example" id="example-manual-write-dont-await">
    <a class="self-link" href="#example-manual-write-dont-await"></a> To further emphasize how it’s a bad idea to <code>await</code> the promise returned by <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write⑤">write()</a></code>, consider a modification of the above example, where we continue to use the <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class①">WritableStreamDefaultWriter</a></code> interface directly, but we don’t control how many bytes we have to write at a given
  time. In that case, the <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①①">backpressure</a>-respecting code looks the same: 
<pre><code class="lang-javascript highlight">async <c- a>function</c-> writeSuppliedBytesForever<c- p>(</c->writableStream<c- p>,</c-> getBytes<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> writer <c- o>=</c-> writableStream<c- p>.</c->getWriter<c- p>();</c->

  <c- k>while</c-> <c- p>(</c-><c- kc>true</c-><c- p>)</c-> <c- p>{</c->
    await writer<c- p>.</c->ready<c- p>;</c->

    <c- kr>const</c-> bytes <c- o>=</c-> getBytes<c- p>();</c->
    writer<c- p>.</c->write<c- p>(</c->bytes<c- p>).</c-><c- k>catch</c-><c- p>(()</c-> <c- p>=></c-> <c- p>{});</c->
  <c- p>}</c->
<c- p>}</c->
</code></pre>
    <p>Unlike the previous example, where—because we were always writing exactly <code class="idl"><a data-link-type="idl" href="#default-writer-desired-size" id="ref-for-default-writer-desired-size③">writer.desiredSize</a></code> bytes each time—the <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write⑥">write()</a></code> and <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready④">ready</a></code> promises were synchronized, in this
  case it’s quite possible that the <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready⑤">ready</a></code> promise fulfills before the one returned by <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write⑦">write()</a></code> does. Remember, the <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready⑥">ready</a></code> promise fulfills
  when the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue⑤">desired size</a> becomes positive, which might be
  before the write succeeds (especially in cases with a larger <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark③">high water mark</a>).</p>
    <p>In other words, <code>await</code>ing the return value of <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write⑧">write()</a></code> means you never
  queue up writes in the stream’s <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues⑦">internal queue</a>, instead only executing a write after the previous one succeeds,
  which can result in low throughput.</p>
   </div>
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="4.2" data-lt="WritableStream" id="ws-class"><span class="secno">4.2. </span><span class="content">Class <code>WritableStream</code></span></h3>
   <h4 class="heading settled" data-level="4.2.1" id="ws-class-definition"><span class="secno">4.2.1. </span><span class="content">Class definition</span><a class="self-link" href="#ws-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①">WritableStream</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it would look
like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> WritableStream <c- p>{</c->
  <a href="#ws-constructor" id="ref-for-ws-constructor④">constructor</a><c- p>(</c-><a href="#underlying-sink-api">underlyingSink</a> <c- o>=</c-> <c- p>{},</c-> <a href="#qs-api">strategy</a> <c- o>=</c-> <c- p>{})</c->

  get <a href="#ws-locked" id="ref-for-ws-locked①">locked</a><c- p>()</c->

  <a href="#ws-abort" id="ref-for-ws-abort②">abort</a><c- p>(</c->reason<c- p>)</c->
  <a href="#ws-close" id="ref-for-ws-close">close</a><c- p>()</c->
  <a href="#ws-get-writer" id="ref-for-ws-get-writer">getWriter</a><c- p>()</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="4.2.2" id="ws-internal-slots"><span class="secno">4.2.2. </span><span class="content">Internal slots</span><a class="self-link" href="#ws-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class②">WritableStream</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[backpressure]] 
      <td class="non-normative">The backpressure signal set by the controller 
     <tr>
      <td>[[closeRequest]] 
      <td class="non-normative">The promise returned from the writer <code class="idl"><a data-link-type="idl" href="#default-writer-close" id="ref-for-default-writer-close③">close()</a></code> method 
     <tr>
      <td>[[inFlightWriteRequest]] 
      <td class="non-normative">A slot set to the promise for the current in-flight write operation while the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink⑦">underlying sink</a>’s write algorithm is executing and has not yet fulfilled, used to prevent reentrant calls 
     <tr>
      <td>[[inFlightCloseRequest]] 
      <td class="non-normative">A slot set to the promise for the current in-flight close operation while the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink⑧">underlying sink</a>’s close algorithm is executing and has not yet fulfilled, used to prevent the <code class="idl"><a data-link-type="idl" href="#default-writer-abort" id="ref-for-default-writer-abort">abort()</a></code> method from interrupting close 
     <tr>
      <td>[[pendingAbortRequest]] 
      <td class="non-normative">A Record containing the promise returned from <code class="idl"><a data-link-type="idl" href="#default-writer-abort" id="ref-for-default-writer-abort①">abort()</a></code> and the <var>reason</var> passed to <code class="idl"><a data-link-type="idl" href="#default-writer-abort" id="ref-for-default-writer-abort②">abort()</a></code> 
     <tr>
      <td>[[state]] 
      <td class="non-normative">A string containing the stream’s current state, used internally; one of <code>"writable"</code>, <code>"closed"</code>, <code>"erroring"</code>, or <code>"errored"</code> 
     <tr>
      <td>[[storedError]] 
      <td class="non-normative">A value indicating how the stream failed, to be given as a failure reason or exception
      when trying to operate on the stream while in the <code>"errored"</code> state 
     <tr>
      <td>[[writableStreamController]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class">WritableStreamDefaultController</a></code> created with the ability to control the state and
      queue of this stream; also used for the <a href="#is-writable-stream">IsWritableStream</a> brand check 
     <tr>
      <td>[[writer]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class②">WritableStreamDefaultWriter</a></code> instance, if the stream is <a data-link-type="dfn" href="#lock" id="ref-for-lock⑨">locked to a writer</a>, or <emu-val>undefined</emu-val> if it is not 
     <tr>
      <td>[[writeRequests]] 
      <td class="non-normative">A List of promises representing the stream’s internal queue of write requests not yet
      processed by the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink⑨">underlying sink</a> 
   </table>
   <p class="note" role="note"> The [[inFlightCloseRequest]] slot and [[closeRequest]] slot are mutually exclusive. Similarly, no element will be
  removed from [[writeRequests]] while [[inFlightWriteRequest]] is not <emu-val>undefined</emu-val>. Implementations
  can optimize storage for these slots based on these invariants. </p>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStream" data-dfn-type="constructor" data-export data-level="4.2.3" data-lt="WritableStream(underlyingSink, strategy)" id="ws-constructor"><span class="secno">4.2.3. </span><span class="content">new
WritableStream(<var>underlyingSink</var> = {}, <var>strategy</var> = {})</span></h4>
   <div class="note" role="note">
     The <code>underlyingSink</code> argument represents the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①⓪">underlying sink</a>, as described in <a href="#underlying-sink-api">§ 4.2.4 Underlying sink API</a>. 
    <p>The <code>strategy</code> argument represents the stream’s <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy④">queuing strategy</a>, as described in <a href="#qs-api">§ 6.1.1 The queuing strategy API</a>. If it
  is not provided, the default behavior will be the same as a <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class②">CountQueuingStrategy</a></code> with a <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark④">high water mark</a> of 1.</p>
   </div>
    <emu-alg>
  1. Perform ! InitializeWritableStream(_this_).
  1. Let _size_ be ? GetV(_strategy_, `"size"`).
  1. Let _highWaterMark_ be ? GetV(_strategy_, `"highWaterMark"`).
  1. Let _type_ be ? GetV(_underlyingSink_, `"type"`).
  1. If _type_ is not *undefined*, throw a *RangeError* exception. <p class="note" role="note">This is to allow us to add new
     potential types in the future, without backward-compatibility concerns.</p>
  1. Let _sizeAlgorithm_ be ? MakeSizeAlgorithmFromSizeFunction(_size_).
  1. If _highWaterMark_ is *undefined*, let _highWaterMark_ be *1*.
  1. Set _highWaterMark_ to ? ValidateAndNormalizeHighWaterMark(_highWaterMark_).
  1. Perform ? SetUpWritableStreamDefaultControllerFromUnderlyingSink(*this*, _underlyingSink_, _highWaterMark_,
     _sizeAlgorithm_).
</emu-alg> 
   <h4 class="heading settled" data-level="4.2.4" id="underlying-sink-api"><span class="secno">4.2.4. </span><span class="content">Underlying sink API</span><a class="self-link" href="#underlying-sink-api"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>The <code class="idl"><a data-link-type="idl" href="#ws-constructor" id="ref-for-ws-constructor①">WritableStream()</a></code> constructor accepts as its first argument a JavaScript object representing the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①①">underlying
sink</a>. Such objects can contain any of the following properties:</p>
    <dl>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="underlying sink" data-dfn-type="method" data-export id="dom-underlying-sink-start"><code>start(<var>controller</var>)</code></dfn>
     <dd>
      <p>A function that is called immediately during creation of the <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class③">WritableStream</a></code>.</p>
      <p>Typically this is used to acquire access to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①②">underlying sink</a> resource being represented.</p>
      <p>If this setup process is asynchronous, it can return a promise to signal success or failure; a rejected promise
    will error the stream. Any thrown exceptions will be re-thrown by the <code class="idl"><a data-link-type="idl" href="#ws-constructor" id="ref-for-ws-constructor②">WritableStream()</a></code> constructor.</p>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="underlying sink" data-dfn-type="method" data-export id="dom-underlying-sink-write"><code>write(<var>chunk</var>, <var>controller</var>)</code></dfn>
     <dd>
      <p>A function that is called when a new <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④⑤">chunk</a> of data is ready to be written to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①③">underlying sink</a>.
    The stream implementation guarantees that this function will be called only after previous writes have succeeded,
    and never before <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-start" id="ref-for-dom-underlying-sink-start">start()</a></code> has succeeded or after <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-close" id="ref-for-dom-underlying-sink-close">close()</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-abort" id="ref-for-dom-underlying-sink-abort">abort()</a></code> have been called.</p>
      <p>This function is used to actually send the data to the resource presented by the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①④">underlying sink</a>, for
    example by calling a lower-level API.</p>
      <p>If the process of writing data is asynchronous, and communicates success or failure signals back to its user,
    then this function can return a promise to signal success or failure. This promise return value will be communicated
    back to the caller of <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write⑨">writer.write()</a></code>, so they can monitor that individual
    write. Throwing an exception is treated the same as returning a rejected promise.</p>
      <p>Note that such signals are not always available; compare e.g. <a href="#example-ws-no-backpressure">§ 8.6 A writable stream with no backpressure or success signals</a> with <a href="#example-ws-backpressure">§ 8.7 A writable stream with backpressure and success signals</a>. In such cases, it’s best to not return anything.</p>
      <p>The promise potentially returned by this function also governs whether the given chunk counts as written for the
    purposes of computed the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue⑥">desired size to fill the stream’s
    internal queue</a>. That is, during the time it takes the promise to settle, <code class="idl"><a data-link-type="idl" href="#default-writer-desired-size" id="ref-for-default-writer-desired-size④">writer.desiredSize</a></code> will stay at its previous value, only increasing to
    signal the desire for more chunks once the write succeeds.</p>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="underlying sink" data-dfn-type="method" data-export id="dom-underlying-sink-close"><code>close()</code></dfn>
     <dd>
      <p>A function that is called after the <a data-link-type="dfn" href="#producer" id="ref-for-producer②">producer</a> signals, via <code class="idl"><a data-link-type="idl" href="#default-writer-close" id="ref-for-default-writer-close④">writer.close()</a></code>, that they are done writing <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④⑥">chunks</a> to the stream, and
    subsequently all queued-up writes have successfully completed.</p>
      <p>This function can perform any actions necessary to finalize or flush writes to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①⑤">underlying sink</a>, and
    release access to any held resources.</p>
      <p>If the shutdown process is asynchronous, the function can return a promise to signal success or failure; the
    result will be communicated via the return value of the called <code class="idl"><a data-link-type="idl" href="#default-writer-close" id="ref-for-default-writer-close⑤">writer.close()</a></code> method. Additionally, a rejected promise will error the
    stream, instead of letting it close successfully. Throwing an exception is treated the same as returning a rejected
    promise.</p>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="underlying sink" data-dfn-type="method" data-export id="dom-underlying-sink-abort"><code>abort(<var>reason</var>)</code></dfn>
     <dd>
      <p>A function that is called after the <a data-link-type="dfn" href="#producer" id="ref-for-producer③">producer</a> signals, via <code class="idl"><a data-link-type="idl" href="#ws-abort" id="ref-for-ws-abort①">stream.abort()</a></code> or <code class="idl"><a data-link-type="idl" href="#default-writer-abort" id="ref-for-default-writer-abort③">writer.abort()</a></code>, that they wish to <a data-link-type="dfn" href="#abort-a-writable-stream" id="ref-for-abort-a-writable-stream③">abort</a> the stream. It takes as its argument the same value as was passed to those methods by the producer.</p>
      <p>Writable streams can additionally be aborted under certain conditions during <a data-link-type="dfn" href="#piping" id="ref-for-piping⑨">piping</a>; see the definition
    of the <code class="idl"><a data-link-type="idl" href="#rs-pipe-to" id="ref-for-rs-pipe-to④">pipeTo()</a></code> method for more details.</p>
      <p>This function can clean up any held resources, much like <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-close" id="ref-for-dom-underlying-sink-close①">close()</a></code>, but perhaps with some
    custom handling.</p>
      <p>If the shutdown process is asynchronous, the function can return a promise to signal success or failure; the
    result will be communicated via the return value of the called <code>abort()</code> method. Throwing an exception is
    treated the same as returning a rejected promise. Regardless, the stream will be errored with a new <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror" id="ref-for-sec-native-error-types-used-in-this-standard-typeerror">TypeError</a></code> indicating that it was aborted.</p>
    </dl>
    <p>The <code>controller</code> argument passed to <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-start" id="ref-for-dom-underlying-sink-start①">start()</a></code> and <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-write" id="ref-for-dom-underlying-sink-write①">write()</a></code> is an
instance of <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class①">WritableStreamDefaultController</a></code>, and has the ability to error the stream. This is mainly used for
bridging the gap with non-promise-based APIs, as seen for example in <a href="#example-ws-no-backpressure">§ 8.6 A writable stream with no backpressure or success signals</a>.</p>
   </div>
   <h4 class="heading settled" data-level="4.2.5" id="ws-prototype"><span class="secno">4.2.5. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class④">WritableStream</a></code> prototype</span><a class="self-link" href="#ws-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStream" data-dfn-type="attribute" data-export data-level="4.2.5.1" data-lt="locked" id="ws-locked"><span class="secno">4.2.5.1. </span><span class="content">get locked</span></h5>
   <div class="note" role="note"> The <code>locked</code> getter returns whether or not the writable stream is <a data-link-type="dfn" href="#lock" id="ref-for-lock①⓪">locked to a writer</a>. </div>
    <emu-alg>
  1. If ! IsWritableStream(*this*) is *false*, throw a *TypeError* exception.
  1. Return ! IsWritableStreamLocked(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStream" data-dfn-type="method" data-export data-level="4.2.5.2" data-lt="abort(reason)" id="ws-abort"><span class="secno">4.2.5.2. </span><span class="content">abort(<var>reason</var>)</span></h5>
   <div class="note" role="note"> The <code>abort</code> method <a data-link-type="dfn" href="#abort-a-writable-stream" id="ref-for-abort-a-writable-stream④">aborts</a> the stream, signaling that the producer can
  no longer successfully write to the stream and it is to be immediately moved to an errored state, with any queued-up
  writes discarded. This will also execute any abort mechanism of the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①⑥">underlying sink</a>. </div>
    <emu-alg>
  1. If ! IsWritableStream(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③③">a promise rejected with</a> a *TypeError* exception.
  1. If ! IsWritableStreamLocked(*this*) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③④">a promise rejected with</a> a *TypeError* exception.
  1. Return ! WritableStreamAbort(*this*, _reason_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStream" data-dfn-type="method" data-export data-level="4.2.5.3" data-lt="close()" id="ws-close"><span class="secno">4.2.5.3. </span><span class="content">close()</span></h5>
   <div class="note" role="note">
     The <code>close</code> method closes the stream. The <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①⑦">underlying sink</a> will finish processing any
  previously-written <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④⑦">chunks</a>, before invoking its close behavior. During this time any further attempts to write
  will fail (without erroring the stream). 
    <p>The method returns a promise that is fulfilled with <emu-val>undefined</emu-val> if all remaining <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④⑧">chunks</a> are
  successfully written and the stream successfully closes, or rejects if an error is encountered during this process.</p>
   </div>
    <emu-alg>
  1. If ! IsWritableStream(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③⑤">a promise rejected with</a> a *TypeError* exception.
  1. If ! IsWritableStreamLocked(*this*) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③⑥">a promise rejected with</a> a *TypeError* exception.
  1. If ! WritableStreamCloseQueuedOrInFlight(*this*) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③⑦">a promise rejected with</a> a *TypeError*
  exception.
  1. Return ! WritableStreamClose(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStream" data-dfn-type="method" data-export data-level="4.2.5.4" data-lt="getWriter()" id="ws-get-writer"><span class="secno">4.2.5.4. </span><span class="content">getWriter()</span></h5>
   <div class="note" role="note">
     The <code>getWriter</code> method creates a <a data-link-type="dfn" href="#writer" id="ref-for-writer③">writer</a> (an instance of <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class③">WritableStreamDefaultWriter</a></code>) and <a data-link-type="dfn" href="#lock" id="ref-for-lock①①">locks</a> the stream to the new writer. While the stream is locked, no other writer can be
  acquired until this one is <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock⑤">released</a>. 
    <p>This functionality is especially useful for creating abstractions that desire the ability to write to a stream without
  interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at the same
  time, which would cause the resulting written data to be unpredictable and probably useless.</p>
   </div>
    <emu-alg>
  1. If ! IsWritableStream(*this*) is *false*, throw a *TypeError* exception.
  1. Return ? AcquireWritableStreamDefaultWriter(*this*).
</emu-alg> 
   <h3 class="heading settled" data-level="4.3" id="ws-abstract-ops"><span class="secno">4.3. </span><span class="content">General writable stream abstract operations</span><a class="self-link" href="#ws-abstract-ops"></a></h3>
   <p>The following abstract operations, unlike most in this specification, are meant to be generally useful by other
specifications, instead of just being part of the implementation of this spec’s classes.</p>
   <h4 aoid="AcquireWritableStreamDefaultWriter" class="heading settled" data-level="4.3.1" id="acquire-writable-stream-default-writer" throws><span class="secno">4.3.1. </span><span class="content">AcquireWritableStreamDefaultWriter ( <var>stream</var> )</span><a class="self-link" href="#acquire-writable-stream-default-writer"></a></h4>
    <emu-alg>
  1. Return ? Construct(`<a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class④">WritableStreamDefaultWriter</a>`, « _stream_ »).
</emu-alg> 
   <h4 aoid="CreateWritableStream" class="heading settled" data-level="4.3.2" id="create-writable-stream" throws><span class="secno">4.3.2. </span><span class="content">CreateWritableStream ( <var>startAlgorithm</var>, <var>writeAlgorithm</var>, <var>closeAlgorithm</var>, <var>abortAlgorithm</var> [, <var>highWaterMark</var> [, <var>sizeAlgorithm</var> ] ] )</span><a class="self-link" href="#create-writable-stream"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that wish to create <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class⑤">WritableStream</a></code> instances. The <var>writeAlgorithm</var>, <var>closeAlgorithm</var> and <var>abortAlgorithm</var> algorithms must return
promises; if supplied, <var>sizeAlgorithm</var> must be an algorithm accepting <a data-link-type="dfn" href="#chunk" id="ref-for-chunk④⑨">chunk</a> objects and returning a
number; and if supplied, <var>highWaterMark</var> must be a non-negative, non-NaN number.</p>
   <p class="note" role="note">CreateWritableStream throws an exception if and only if the supplied <var>startAlgorithm</var> throws.</p>
    <emu-alg>
  1. If _highWaterMark_ was not passed, set it to *1*.
  1. If _sizeAlgorithm_ was not passed, set it to an algorithm that returns *1*.
  1. Assert: ! IsNonNegativeNumber(_highWaterMark_) is *true*.
  1. Let _stream_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#ws-class" id="ref-for-ws-class⑥">WritableStream</a>`'s `prototype` property).
  1. Perform ! InitializeWritableStream(_stream_).
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class②">WritableStreamDefaultController</a>`'s `prototype`
     property).
  1. Perform ? SetUpWritableStreamDefaultController(_stream_, _controller_, _startAlgorithm_, _writeAlgorithm_,
     _closeAlgorithm_, _abortAlgorithm_, _highWaterMark_, _sizeAlgorithm_).
  1. Return _stream_.
</emu-alg> 
   <h4 aoid="InitializeWritableStream" class="heading settled" data-level="4.3.3" id="initialize-writable-stream" nothrow><span class="secno">4.3.3. </span><span class="content">InitializeWritableStream ( <var>stream</var> )</span><a class="self-link" href="#initialize-writable-stream"></a></h4>
    <emu-alg>
  1. Set _stream_.[[state]] to `"writable"`.
  1. Set _stream_.[[storedError]], _stream_.[[writer]], _stream_.[[writableStreamController]],
     _stream_.[[inFlightWriteRequest]], _stream_.[[closeRequest]], _stream_.[[inFlightCloseRequest]] and
     _stream_.[[pendingAbortRequest]] to *undefined*.
  1. Set _stream_.[[writeRequests]] to a new empty List.
  1. Set _stream_.[[backpressure]] to *false*.
</emu-alg> 
   <h4 aoid="IsWritableStream" class="heading settled" data-level="4.3.4" id="is-writable-stream" nothrow><span class="secno">4.3.4. </span><span class="content">IsWritableStream ( <var>x</var> )</span><a class="self-link" href="#is-writable-stream"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have a [[writableStreamController]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="IsWritableStreamLocked" class="heading settled" data-level="4.3.5" id="is-writable-stream-locked" nothrow><span class="secno">4.3.5. </span><span class="content">IsWritableStreamLocked ( <var>stream</var> )</span><a class="self-link" href="#is-writable-stream-locked"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that may wish to query whether or not a
writable stream is <a data-link-type="dfn" href="#lock" id="ref-for-lock①②">locked to a writer</a>.</p>
    <emu-alg>
  1. Assert: ! IsWritableStream(_stream_) is *true*.
  1. If _stream_.[[writer]] is *undefined*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="WritableStreamAbort" class="heading settled" data-level="4.3.6" id="writable-stream-abort" nothrow><span class="secno">4.3.6. </span><span class="content">WritableStreamAbort ( <var>stream</var>, <var>reason</var> )</span><a class="self-link" href="#writable-stream-abort"></a></h4>
    <emu-alg>
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"closed"` or `"errored"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①⑤">a promise resolved with</a> *undefined*.
  1. If _stream_.[[pendingAbortRequest]] is not *undefined*, return _stream_.[[pendingAbortRequest]].[[promise]].
  1. Assert: _state_ is `"writable"` or `"erroring"`.
  1. Let _wasAlreadyErroring_ be *false*.
  1. If _state_ is `"erroring"`,
    1. Set _wasAlreadyErroring_ to *true*.
    1. Set _reason_ to *undefined*.
  1. Let _promise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise⑤">a new promise</a>.
  1. Set _stream_.[[pendingAbortRequest]] to Record {[[promise]]: _promise_, [[reason]]: _reason_,
     [[wasAlreadyErroring]]: _wasAlreadyErroring_}.
  1. If _wasAlreadyErroring_ is *false*, perform ! WritableStreamStartErroring(_stream_, _reason_).
  1. Return _promise_.
</emu-alg> 
   <h4 aoid="WritableStreamClose" class="heading settled" data-level="4.3.7" id="writable-stream-close" nothrow><span class="secno">4.3.7. </span><span class="content">WritableStreamClose ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-close"></a></h4>
    <emu-alg>
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"closed"` or `"errored"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③⑧">a promise rejected with</a> a *TypeError* exception.
  1. Assert: _state_ is `"writable"` or `"erroring"`.
  1. Assert: ! WritableStreamCloseQueuedOrInFlight(_stream_) is *false*.
  1. Let _promise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise⑥">a new promise</a>.
  1. Set _stream_.[[closeRequest]] to _promise_.
  1. Let _writer_ be _stream_.[[writer]].
  1. If _writer_ is not *undefined*, and _stream_.[[backpressure]] is *true*, and _state_ is `"writable"`,
     <a data-link-type="dfn">resolve</a> _writer_.[[readyPromise]] with *undefined*.
  1. Perform ! WritableStreamDefaultControllerClose(_stream_.[[writableStreamController]]).
  1. Return _promise_.
</emu-alg> 
   <h3 class="heading settled" data-level="4.4" id="ws-abstract-ops-used-by-controllers"><span class="secno">4.4. </span><span class="content">Writable stream abstract operations used by controllers</span><a class="self-link" href="#ws-abstract-ops-used-by-controllers"></a></h3>
   <p>To allow future flexibility to add different writable stream behaviors (similar to the distinction between default
readable streams and <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream⑥">readable byte streams</a>), much of the internal state of a <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①①">writable stream</a> is
encapsulated by the <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class③">WritableStreamDefaultController</a></code> class.</p>
   <p>The abstract operations in this section are interfaces that are used by the controller implementation to affect its
associated <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class⑦">WritableStream</a></code> object, translating the controller’s internal state changes into developer-facing results
visible through the <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class⑧">WritableStream</a></code>'s public API.</p>
   <h4 aoid="WritableStreamAddWriteRequest" class="heading settled" data-level="4.4.1" id="writable-stream-add-write-request" nothrow><span class="secno">4.4.1. </span><span class="content">WritableStreamAddWriteRequest ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-add-write-request"></a></h4>
    <emu-alg>
  1. Assert: ! IsWritableStreamLocked(_stream_) is *true*.
  1. Assert: _stream_.[[state]] is `"writable"`.
  1. Let _promise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise⑦">a new promise</a>.
  1. Append _promise_ as the last element of _stream_.[[writeRequests]].
  1. Return _promise_.
</emu-alg> 
   <h4 aoid="WritableStreamDealWithRejection" class="heading settled" data-level="4.4.2" id="writable-stream-deal-with-rejection" nothrow><span class="secno">4.4.2. </span><span class="content">WritableStreamDealWithRejection ( <var>stream</var>, <var>error</var> )</span><a class="self-link" href="#writable-stream-deal-with-rejection"></a></h4>
    <emu-alg>
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"writable"`,
    1. Perform ! WritableStreamStartErroring(_stream_, _error_).
    1. Return.
  1. Assert: _state_ is `"erroring"`.
  1. Perform ! WritableStreamFinishErroring(_stream_).
</emu-alg> 
   <h4 aoid="WritableStreamStartErroring" class="heading settled" data-level="4.4.3" id="writable-stream-start-erroring" nothrow><span class="secno">4.4.3. </span><span class="content">WritableStreamStartErroring ( <var>stream</var>, <var>reason</var> )</span><a class="self-link" href="#writable-stream-start-erroring"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[storedError]] is *undefined*.
  1. Assert: _stream_.[[state]] is `"writable"`.
  1. Let _controller_ be _stream_.[[writableStreamController]].
  1. Assert: _controller_ is not *undefined*.
  1. Set _stream_.[[state]] to `"erroring"`.
  1. Set _stream_.[[storedError]] to _reason_.
  1. Let _writer_ be _stream_.[[writer]].
  1. If _writer_ is not *undefined*, perform !
     WritableStreamDefaultWriterEnsureReadyPromiseRejected(_writer_, _reason_).
  1. If ! WritableStreamHasOperationMarkedInFlight(_stream_) is *false* and _controller_.[[started]] is *true*, perform
     ! WritableStreamFinishErroring(_stream_).
</emu-alg> 
   <h4 aoid="WritableStreamFinishErroring" class="heading settled" data-level="4.4.4" id="writable-stream-finish-erroring" nothrow><span class="secno">4.4.4. </span><span class="content">WritableStreamFinishErroring
( <var>stream</var> )</span><a class="self-link" href="#writable-stream-finish-erroring"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[state]] is `"erroring"`.
  1. Assert: ! WritableStreamHasOperationMarkedInFlight(_stream_) is *false*.
  1. Set _stream_.[[state]] to `"errored"`.
  1. Perform ! _stream_.[[writableStreamController]].[[ErrorSteps]]().
  1. Let _storedError_ be _stream_.[[storedError]].
  1. Repeat for each _writeRequest_ that is an element of _stream_.[[writeRequests]],
    1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise⑤">Reject</a> _writeRequest_ with _storedError_.
  1. Set _stream_.[[writeRequests]] to an empty List.
  1. If _stream_.[[pendingAbortRequest]] is *undefined*,
    1. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(_stream_).
    1. Return.
  1. Let _abortRequest_ be _stream_.[[pendingAbortRequest]].
  1. Set _stream_.[[pendingAbortRequest]] to *undefined*.
  1. If _abortRequest_.[[wasAlreadyErroring]] is *true*,
    1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise⑥">Reject</a> _abortRequest_.[[promise]] with _storedError_.
    1. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(_stream_).
    1. Return.
  1. Let _promise_ be ! stream.[[writableStreamController]].[[AbortSteps]](_abortRequest_.[[reason]]).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment⑤">Upon fulfillment</a> of _promise_,
    1. <a data-link-type="dfn">Resolve</a> _abortRequest_.[[promise]] with *undefined*.
    1. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(_stream_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection⑥">Upon rejection</a> of _promise_ with reason _reason_,
    1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise⑦">Reject</a> _abortRequest_.[[promise]] with _reason_.
    1. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(_stream_).
</emu-alg> 
   <h4 aoid="WritableStreamFinishInFlightWrite" class="heading settled" data-level="4.4.5" id="writable-stream-finish-in-flight-write" nothrow><span class="secno">4.4.5. </span><span class="content">WritableStreamFinishInFlightWrite ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-finish-in-flight-write"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[inFlightWriteRequest]] is not *undefined*.
  1. <a data-link-type="dfn">Resolve</a> _stream_.[[inFlightWriteRequest]] with *undefined*.
  1. Set _stream_.[[inFlightWriteRequest]] to *undefined*.
</emu-alg> 
   <h4 aoid="WritableStreamFinishInFlightWriteWithError" class="heading settled" data-level="4.4.6" id="writable-stream-finish-in-flight-write-with-error" nothrow><span class="secno">4.4.6. </span><span class="content">WritableStreamFinishInFlightWriteWithError ( <var>stream</var>, <var>error</var> )</span><a class="self-link" href="#writable-stream-finish-in-flight-write-with-error"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[inFlightWriteRequest]] is not *undefined*.
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise⑧">Reject</a> _stream_.[[inFlightWriteRequest]] with _error_.
  1. Set _stream_.[[inFlightWriteRequest]] to *undefined*.
  1. Assert: _stream_.[[state]] is `"writable"` or `"erroring"`.
  1. Perform ! WritableStreamDealWithRejection(_stream_, _error_).
</emu-alg> 
   <h4 aoid="WritableStreamFinishInFlightClose" class="heading settled" data-level="4.4.7" id="writable-stream-finish-in-flight-close" nothrow><span class="secno">4.4.7. </span><span class="content">WritableStreamFinishInFlightClose ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-finish-in-flight-close"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[inFlightCloseRequest]] is not *undefined*.
  1. <a data-link-type="dfn">Resolve</a> _stream_.[[inFlightCloseRequest]] with *undefined*.
  1. Set _stream_.[[inFlightCloseRequest]] to *undefined*.
  1. Let _state_ be _stream_.[[state]].
  1. Assert: _stream_.[[state]] is `"writable"` or `"erroring"`.
  1. If _state_ is `"erroring"`,
    1. Set _stream_.[[storedError]] to *undefined*.
    1. If _stream_.[[pendingAbortRequest]] is not *undefined*,
      1. <a data-link-type="dfn">Resolve</a> _stream_.[[pendingAbortRequest]].[[promise]] with *undefined*.
      1. Set _stream_.[[pendingAbortRequest]] to *undefined*.
  1. Set _stream_.[[state]] to `"closed"`.
  1. Let _writer_ be _stream_.[[writer]].
  1. If _writer_ is not *undefined*, <a data-link-type="dfn">resolve</a> _writer_.[[closedPromise]] with *undefined*.
  1. Assert: _stream_.[[pendingAbortRequest]] is *undefined*.
  1. Assert: _stream_.[[storedError]] is *undefined*.
</emu-alg> 
   <h4 aoid="WritableStreamFinishInFlightCloseWithError" class="heading settled" data-level="4.4.8" id="writable-stream-finish-in-flight-close-with-error" nothrow><span class="secno">4.4.8. </span><span class="content">WritableStreamFinishInFlightCloseWithError ( <var>stream</var>, <var>error</var> )</span><a class="self-link" href="#writable-stream-finish-in-flight-close-with-error"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[inFlightCloseRequest]] is not *undefined*.
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise⑨">Reject</a> _stream_.[[inFlightCloseRequest]] with _error_.
  1. Set _stream_.[[inFlightCloseRequest]] to *undefined*.
  1. Assert: _stream_.[[state]] is `"writable"` or `"erroring"`.
  1. If _stream_.[[pendingAbortRequest]] is not *undefined*,
    1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise①⓪">Reject</a> _stream_.[[pendingAbortRequest]].[[promise]] with _error_.
    1. Set _stream_.[[pendingAbortRequest]] to *undefined*.
  1. Perform ! WritableStreamDealWithRejection(_stream_, _error_).
</emu-alg> 
   <h4 aoid="WritableStreamCloseQueuedOrInFlight" class="heading settled" data-level="4.4.9" id="writable-stream-close-queued-or-in-flight" nothrow><span class="secno">4.4.9. </span><span class="content"> WritableStreamCloseQueuedOrInFlight ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-close-queued-or-in-flight"></a></h4>
    <emu-alg>
  1. If _stream_.[[closeRequest]] is *undefined* and _stream_.[[inFlightCloseRequest]] is *undefined*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="WritableStreamHasOperationMarkedInFlight" class="heading settled" data-level="4.4.10" id="writable-stream-has-operation-marked-in-flight" nothrow><span class="secno">4.4.10. </span><span class="content">WritableStreamHasOperationMarkedInFlight ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-has-operation-marked-in-flight"></a></h4>
    <emu-alg>
  1. If _stream_.[[inFlightWriteRequest]] is *undefined* and _controller_.[[inFlightCloseRequest]] is *undefined*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="WritableStreamMarkCloseRequestInFlight" class="heading settled" data-level="4.4.11" id="writable-stream-mark-close-request-in-flight" nothrow><span class="secno">4.4.11. </span><span class="content">WritableStreamMarkCloseRequestInFlight ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-mark-close-request-in-flight"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[inFlightCloseRequest]] is *undefined*.
  1. Assert: _stream_.[[closeRequest]] is not *undefined*.
  1. Set _stream_.[[inFlightCloseRequest]] to _stream_.[[closeRequest]].
  1. Set _stream_.[[closeRequest]] to *undefined*.
</emu-alg> 
   <h4 aoid="WritableStreamMarkFirstWriteRequestInFlight" class="heading settled" data-level="4.4.12" id="writable-stream-mark-first-write-request-in-flight" nothrow><span class="secno">4.4.12. </span><span class="content">WritableStreamMarkFirstWriteRequestInFlight ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-mark-first-write-request-in-flight"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[inFlightWriteRequest]] is *undefined*.
  1. Assert: _stream_.[[writeRequests]] is not empty.
  1. Let _writeRequest_ be the first element of _stream_.[[writeRequests]].
  1. Remove _writeRequest_ from _stream_.[[writeRequests]], shifting all other elements downward (so that the second
     becomes the first, and so on).
  1. Set _stream_.[[inFlightWriteRequest]] to _writeRequest_.
</emu-alg> 
   <h4 aoid="WritableStreamRejectCloseAndClosedPromiseIfNeeded" class="heading settled" data-level="4.4.13" id="writable-stream-reject-close-and-closed-promise-if-needed" nothrow><span class="secno">4.4.13. </span><span class="content">WritableStreamRejectCloseAndClosedPromiseIfNeeded ( <var>stream</var> )</span><a class="self-link" href="#writable-stream-reject-close-and-closed-promise-if-needed"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[state]] is `"errored"`.
  1. If _stream_.[[closeRequest]] is not *undefined*,
    1. Assert: _stream_.[[inFlightCloseRequest]] is *undefined*.
    1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise①①">Reject</a> _stream_.[[closeRequest]] with _stream_.[[storedError]].
    1. Set _stream_.[[closeRequest]] to *undefined*.
  1. Let _writer_ be _stream_.[[writer]].
  1. If _writer_ is not *undefined*,
    1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise①②">Reject</a> _writer_.[[closedPromise]] with _stream_.[[storedError]].
    1. Set _writer_.[[closedPromise]].[[PromiseIsHandled]] to *true*.
</emu-alg> 
   <h4 aoid="WritableStreamUpdateBackpressure" class="heading settled" data-level="4.4.14" id="writable-stream-update-backpressure" nothrow><span class="secno">4.4.14. </span><span class="content">WritableStreamUpdateBackpressure ( <var>stream</var>, <var>backpressure</var> )</span><a class="self-link" href="#writable-stream-update-backpressure"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[state]] is `"writable"`.
  1. Assert: ! WritableStreamCloseQueuedOrInFlight(_stream_) is *false*.
  1. Let _writer_ be _stream_.[[writer]].
  1. If _writer_ is not *undefined* and _backpressure_ is not _stream_.[[backpressure]],
    1. If _backpressure_ is *true*, set _writer_.[[readyPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise⑧">a new promise</a>.
    1. Otherwise,
      1. Assert: _backpressure_ is *false*.
      1. <a data-link-type="dfn">Resolve</a> _writer_.[[readyPromise]] with *undefined*.
  1. Set _stream_.[[backpressure]] to _backpressure_.
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="4.5" data-lt="WritableStreamDefaultWriter" id="default-writer-class"><span class="secno">4.5. </span><span class="content">Class <code>WritableStreamDefaultWriter</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class⑤">WritableStreamDefaultWriter</a></code> class represents a <a data-link-type="dfn" href="#writer" id="ref-for-writer④">writable stream writer</a> designed to be vended by a <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class⑨">WritableStream</a></code> instance.</p>
   <h4 class="heading settled" data-level="4.5.1" id="default-writer-class-definition"><span class="secno">4.5.1. </span><span class="content">Class definition</span><a class="self-link" href="#default-writer-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class⑥">WritableStreamDefaultWriter</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it
would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> WritableStreamDefaultWriter <c- p>{</c->
  <a href="#default-writer-constructor" id="ref-for-default-writer-constructor">constructor</a><c- p>(</c->stream<c- p>)</c->

  get <a href="#default-writer-closed" id="ref-for-default-writer-closed">closed</a><c- p>()</c->
  get <a href="#default-writer-desired-size" id="ref-for-default-writer-desired-size⑥">desiredSize</a><c- p>()</c->
  get <a href="#default-writer-ready" id="ref-for-default-writer-ready①⓪">ready</a><c- p>()</c->

  <a href="#default-writer-abort" id="ref-for-default-writer-abort④">abort</a><c- p>(</c->reason<c- p>)</c->
  <a href="#default-writer-close" id="ref-for-default-writer-close⑥">close</a><c- p>()</c->
  <a href="#default-writer-release-lock" id="ref-for-default-writer-release-lock①">releaseLock</a><c- p>()</c->
  <a href="#default-writer-write" id="ref-for-default-writer-write①③">write</a><c- p>(</c->chunk<c- p>)</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="4.5.2" id="default-writer-internal-slots"><span class="secno">4.5.2. </span><span class="content">Internal slots</span><a class="self-link" href="#default-writer-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class⑦">WritableStreamDefaultWriter</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[closedPromise]] 
      <td class="non-normative">A promise returned by the writer’s <code class="idl"><a data-link-type="idl" href="#default-writer-closed" id="ref-for-default-writer-closed①">closed</a></code> getter 
     <tr>
      <td>[[ownerWritableStream]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①⓪">WritableStream</a></code> instance that owns this writer 
     <tr>
      <td>[[readyPromise]] 
      <td class="non-normative">A promise returned by the writer’s <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready⑦">ready</a></code> getter 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="constructor" data-export data-level="4.5.3" data-lt="WritableStreamDefaultWriter(stream)" id="default-writer-constructor"><span class="secno">4.5.3. </span><span class="content">new WritableStreamDefaultWriter(<var>stream</var>)</span></h4>
   <div class="note" role="note"> The <code>WritableStreamDefaultWriter</code> constructor is generally not meant to be used directly; instead, a
  stream’s <code class="idl"><a data-link-type="idl" href="#ws-get-writer" id="ref-for-ws-get-writer①">getWriter()</a></code> method ought to be used. </div>
    <emu-alg>
  1. If ! IsWritableStream(_stream_) is *false*, throw a *TypeError* exception.
  1. If ! IsWritableStreamLocked(_stream_) is *true*, throw a *TypeError* exception.
  1. Set *this*.[[ownerWritableStream]] to _stream_.
  1. Set _stream_.[[writer]] to *this*.
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"writable"`,
    1. If ! WritableStreamCloseQueuedOrInFlight(_stream_) is *false* and _stream_.[[backpressure]] is *true*,
       set *this*.[[readyPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise⑨">a new promise</a>.
    1. Otherwise, set *this*.[[readyPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①⑥">a promise resolved with</a> *undefined*.
    1. Set *this*.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise①⓪">a new promise</a>.
  1. Otherwise, if _state_ is `"erroring"`,
      1. Set *this*.[[readyPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with③⑨">a promise rejected with</a> _stream_.[[storedError]].
      1. Set *this*.[[readyPromise]].[[PromiseIsHandled]] to *true*.
      1. Set *this*.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise①①">a new promise</a>.
  1. Otherwise, if _state_ is `"closed"`,
    1. Set *this*.[[readyPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①⑦">a promise resolved with</a> *undefined*.
    1. Set *this*.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①⑧">a promise resolved with</a> *undefined*.
  1. Otherwise,
    1. Assert: _state_ is `"errored"`.
    1. Let _storedError_ be _stream_.[[storedError]].
    1. Set *this*.[[readyPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④⓪">a promise rejected with</a> _storedError_.
    1. Set *this*.[[readyPromise]].[[PromiseIsHandled]] to *true*.
    1. Set *this*.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④①">a promise rejected with</a> _storedError_.
    1. Set *this*.[[closedPromise]].[[PromiseIsHandled]] to *true*.
</emu-alg> 
   <h4 class="heading settled" data-level="4.5.4" id="default-writer-prototype"><span class="secno">4.5.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class⑧">WritableStreamDefaultWriter</a></code> prototype</span><a class="self-link" href="#default-writer-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="attribute" data-export data-level="4.5.4.1" data-lt="closed" id="default-writer-closed"><span class="secno">4.5.4.1. </span><span class="content">get closed</span></h5>
   <div class="note" role="note"> The <code>closed</code> getter returns a promise that will be fulfilled when the stream becomes closed, or rejected if
  the stream ever errors or the writer’s lock is <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock⑥">released</a> before the stream finishes
  closing. </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultWriter(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④②">a promise rejected with</a> a *TypeError* exception.
  1. Return *this*.[[closedPromise]].
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="attribute" data-export data-level="4.5.4.2" data-lt="desiredSize" id="default-writer-desired-size"><span class="secno">4.5.4.2. </span><span class="content">get desiredSize</span></h5>
   <div class="note" role="note">
     The <code>desiredSize</code> getter returns the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue⑦">desired size to
  fill the stream’s internal queue</a>. It can be negative, if the queue is over-full. A <a data-link-type="dfn" href="#producer" id="ref-for-producer④">producer</a> can use this
  information to determine the right amount of data to write. 
    <p>It will be <emu-val>null</emu-val> if the stream cannot be successfully written to (due to either being errored, or
  having an abort queued up). It will return zero if the stream is closed. The getter will throw an exception if invoked
  when the writer’s lock is <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock⑦">released</a>.</p>
   </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultWriter(*this*) is *false*, throw a *TypeError* exception.
  1. If *this*.[[ownerWritableStream]] is *undefined*, throw a *TypeError* exception.
  1. Return ! WritableStreamDefaultWriterGetDesiredSize(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="attribute" data-export data-level="4.5.4.3" data-lt="ready" id="default-writer-ready"><span class="secno">4.5.4.3. </span><span class="content">get ready</span></h5>
   <div class="note" role="note">
     The <code>ready</code> getter returns a promise that will be fulfilled when the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue⑧">desired size to fill the stream’s internal queue</a> transitions from non-positive to positive,
  signaling that it is no longer applying <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①②">backpressure</a>. Once the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue⑨">desired size to fill the stream’s internal queue</a> dips back to zero or below, the getter will return a new
  promise that stays pending until the next transition. 
    <p>If the stream becomes errored or aborted, or the writer’s lock is <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock⑧">released</a>, the
  returned promise will become rejected.</p>
   </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultWriter(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④③">a promise rejected with</a> a *TypeError* exception.
  1. Return *this*.[[readyPromise]].
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="method" data-export data-level="4.5.4.4" data-lt="abort(reason)" id="default-writer-abort"><span class="secno">4.5.4.4. </span><span class="content">abort(<var>reason</var>)</span></h5>
   <div class="note" role="note"> If the writer is <a data-link-type="dfn" href="#active" id="ref-for-active④">active</a>, the <code>abort</code> method behaves the same as that for the
  associated stream. (Otherwise, it returns a rejected promise.) </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultWriter(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④④">a promise rejected with</a> a *TypeError* exception.
  1. If *this*.[[ownerWritableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④⑤">a promise rejected with</a> a *TypeError* exception.
  1. Return ! WritableStreamDefaultWriterAbort(*this*, _reason_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="method" data-export data-level="4.5.4.5" data-lt="close()" id="default-writer-close"><span class="secno">4.5.4.5. </span><span class="content">close()</span></h5>
   <div class="note" role="note"> If the writer is <a data-link-type="dfn" href="#active" id="ref-for-active⑤">active</a>, the <code>close</code> method behaves the same as that for the
  associated stream. (Otherwise, it returns a rejected promise.) </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultWriter(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④⑥">a promise rejected with</a> a *TypeError* exception.
  1. Let _stream_ be *this*.[[ownerWritableStream]].
  1. If _stream_ is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④⑦">a promise rejected with</a> a *TypeError* exception.
  1. If ! WritableStreamCloseQueuedOrInFlight(_stream_) is *true*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④⑧">a promise rejected with</a> a *TypeError*
     exception.
  1. Return ! WritableStreamDefaultWriterClose(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="method" data-export data-level="4.5.4.6" data-lt="releaseLock()" id="default-writer-release-lock"><span class="secno">4.5.4.6. </span><span class="content">releaseLock()</span></h5>
   <div class="note" role="note">
     The <code>releaseLock</code> method <a data-link-type="dfn" href="#release-a-lock" id="ref-for-release-a-lock⑨">releases the writer’s lock</a> on the corresponding
  stream. After the lock is released, the writer is no longer <a data-link-type="dfn" href="#active" id="ref-for-active⑥">active</a>. If the associated
  stream is errored when the lock is released, the writer will appear errored in the same way from now on; otherwise,
  the writer will appear closed. 
    <p>Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the promises
  returned from previous calls to <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write①⓪">write()</a></code> have not yet settled). It’s not necessary to
  hold the lock on the writer for the duration of the write; the lock instead simply prevents other <a data-link-type="dfn" href="#producer" id="ref-for-producer⑤">producers</a> from writing in an interleaved manner.</p>
   </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultWriter(*this*) is *false*, throw a *TypeError* exception.
  1. Let _stream_ be *this*.[[ownerWritableStream]].
  1. If _stream_ is *undefined*, return.
  1. Assert: _stream_.[[writer]] is not *undefined*.
  1. Perform ! WritableStreamDefaultWriterRelease(*this*).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultWriter" data-dfn-type="method" data-export data-level="4.5.4.7" data-lt="write(chunk)" id="default-writer-write"><span class="secno">4.5.4.7. </span><span class="content">write(<var>chunk</var>)</span></h5>
   <div class="note" role="note">
     The <code>write</code> method writes the given <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤⓪">chunk</a> to the writable stream, by waiting until any previous
  writes have finished successfully, and then sending the <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤①">chunk</a> to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①⑧">underlying sink</a>’s <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-write" id="ref-for-dom-underlying-sink-write②">write()</a></code> method. It will return a promise that fulfills with <emu-val>undefined</emu-val> upon a successful
  write, or rejects if the write fails or stream becomes errored before the writing process is initiated. 
    <p>Note that what "success" means is up to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink①⑨">underlying sink</a>; it might indicate simply that the <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤②">chunk</a> has
  been accepted, and not necessarily that it is safely saved to its ultimate destination.</p>
   </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultWriter(*this*) is *false*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with④⑨">a promise rejected with</a> a *TypeError* exception.
  1. If *this*.[[ownerWritableStream]] is *undefined*, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤⓪">a promise rejected with</a> a *TypeError* exception.
  1. Return ! WritableStreamDefaultWriterWrite(*this*, _chunk_).
</emu-alg> 
   <h3 class="heading settled" data-level="4.6" id="rs-writer-abstract-ops"><span class="secno">4.6. </span><span class="content">Writable stream writer abstract operations</span><a class="self-link" href="#rs-writer-abstract-ops"></a></h3>
   <h4 aoid="IsWritableStreamDefaultWriter" class="heading settled" data-level="4.6.1" id="is-writable-stream-default-writer" nothrow><span class="secno">4.6.1. </span><span class="content">IsWritableStreamDefaultWriter ( <var>x</var> )</span><a class="self-link" href="#is-writable-stream-default-writer"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have an [[ownerWritableStream]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterAbort" class="heading settled" data-level="4.6.2" id="writable-stream-default-writer-abort" nothrow><span class="secno">4.6.2. </span><span class="content">WritableStreamDefaultWriterAbort ( <var>writer</var>, <var>reason</var> )</span><a class="self-link" href="#writable-stream-default-writer-abort"></a></h4>
    <emu-alg>
  1. Let _stream_ be _writer_.[[ownerWritableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Return ! WritableStreamAbort(_stream_, _reason_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterClose" class="heading settled" data-level="4.6.3" id="writable-stream-default-writer-close" nothrow><span class="secno">4.6.3. </span><span class="content">WritableStreamDefaultWriterClose ( <var>writer</var> )</span><a class="self-link" href="#writable-stream-default-writer-close"></a></h4>
    <emu-alg>
  1. Let _stream_ be _writer_.[[ownerWritableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Return ! WritableStreamClose(_stream_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterCloseWithErrorPropagation" class="heading settled" data-level="4.6.4" id="writable-stream-default-writer-close-with-error-propagation" nothrow><span class="secno">4.6.4. </span><span class="content">WritableStreamDefaultWriterCloseWithErrorPropagation ( <var>writer</var> )</span><a class="self-link" href="#writable-stream-default-writer-close-with-error-propagation"></a></h4>
   <p class="note" role="note">This abstract operation helps implement the error propagation semantics of <code class="idl"><a data-link-type="idl" href="#rs-pipe-to" id="ref-for-rs-pipe-to⑤">pipeTo()</a></code>.</p>
    <emu-alg>
  1. Let _stream_ be _writer_.[[ownerWritableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Let _state_ be _stream_.[[state]].
  1. If ! WritableStreamCloseQueuedOrInFlight(_stream_) is *true* or _state_ is `"closed"`, return
     <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with①⑨">a promise resolved with</a> *undefined*.
  1. If _state_ is `"errored"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤①">a promise rejected with</a> _stream_.[[storedError]].
  1. Assert: _state_ is `"writable"` or `"erroring"`.
  1. Return ! WritableStreamDefaultWriterClose(_writer_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterEnsureClosedPromiseRejected" class="heading settled" data-level="4.6.5" id="writable-stream-default-writer-ensure-closed-promise-rejected" nothrow><span class="secno">4.6.5. </span><span class="content">WritableStreamDefaultWriterEnsureClosedPromiseRejected( <var>writer</var>, <var>error</var> )</span><a class="self-link" href="#writable-stream-default-writer-ensure-closed-promise-rejected"></a></h4>
    <emu-alg>
  1. If _writer_.[[closedPromise]].[[PromiseState]] is `"pending"`, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise①③">reject</a> _writer_.[[closedPromise]] with
     _error_.
  1. Otherwise, set _writer_.[[closedPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤②">a promise rejected with</a> _error_.
  1. Set _writer_.[[closedPromise]].[[PromiseIsHandled]] to *true*.
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterEnsureReadyPromiseRejected" class="heading settled" data-level="4.6.6" id="writable-stream-default-writer-ensure-ready-promise-rejected" nothrow><span class="secno">4.6.6. </span><span class="content">WritableStreamDefaultWriterEnsureReadyPromiseRejected( <var>writer</var>, <var>error</var> )</span><a class="self-link" href="#writable-stream-default-writer-ensure-ready-promise-rejected"></a></h4>
    <emu-alg>
  1. If _writer_.[[readyPromise]].[[PromiseState]] is `"pending"`, <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise" id="ref-for-reject-promise①④">reject</a> _writer_.[[readyPromise]] with _error_.
  1. Otherwise, set _writer_.[[readyPromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤③">a promise rejected with</a> _error_.
  1. Set _writer_.[[readyPromise]].[[PromiseIsHandled]] to *true*.
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterGetDesiredSize" class="heading settled" data-level="4.6.7" id="writable-stream-default-writer-get-desired-size" nothrow><span class="secno">4.6.7. </span><span class="content">WritableStreamDefaultWriterGetDesiredSize ( <var>writer</var> )</span><a class="self-link" href="#writable-stream-default-writer-get-desired-size"></a></h4>
    <emu-alg>
  1. Let _stream_ be _writer_.[[ownerWritableStream]].
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"errored"` or `"erroring"`, return *null*.
  1. If _state_ is `"closed"`, return *0*.
  1. Return ! WritableStreamDefaultControllerGetDesiredSize(_stream_.[[writableStreamController]]).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterRelease" class="heading settled" data-level="4.6.8" id="writable-stream-default-writer-release" nothrow><span class="secno">4.6.8. </span><span class="content">WritableStreamDefaultWriterRelease ( <var>writer</var> )</span><a class="self-link" href="#writable-stream-default-writer-release"></a></h4>
    <emu-alg>
  1. Let _stream_ be _writer_.[[ownerWritableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Assert: _stream_.[[writer]] is _writer_.
  1. Let _releasedError_ be a new *TypeError*.
  1. Perform ! WritableStreamDefaultWriterEnsureReadyPromiseRejected(_writer_, _releasedError_).
  1. Perform ! WritableStreamDefaultWriterEnsureClosedPromiseRejected(_writer_, _releasedError_).
  1. Set _stream_.[[writer]] to *undefined*.
  1. Set _writer_.[[ownerWritableStream]] to *undefined*.
</emu-alg> 
   <h4 aoid="WritableStreamDefaultWriterWrite" class="heading settled" data-level="4.6.9" id="writable-stream-default-writer-write" nothrow><span class="secno">4.6.9. </span><span class="content">WritableStreamDefaultWriterWrite ( <var>writer</var>, <var>chunk</var> )</span><a class="self-link" href="#writable-stream-default-writer-write"></a></h4>
    <emu-alg>
  1. Let _stream_ be _writer_.[[ownerWritableStream]].
  1. Assert: _stream_ is not *undefined*.
  1. Let _controller_ be _stream_.[[writableStreamController]].
  1. Let _chunkSize_ be ! WritableStreamDefaultControllerGetChunkSize(_controller_, _chunk_).
  1. If _stream_ is not equal to _writer_.[[ownerWritableStream]], return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤④">a promise rejected with</a> a *TypeError*
     exception.
  1. Let _state_ be _stream_.[[state]].
  1. If _state_ is `"errored"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤⑤">a promise rejected with</a> _stream_.[[storedError]].
  1. If ! WritableStreamCloseQueuedOrInFlight(_stream_) is *true* or _state_ is `"closed"`, return
     <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤⑥">a promise rejected with</a> a *TypeError* exception indicating that the stream is closing or closed.
  1. If _state_ is `"erroring"`, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤⑦">a promise rejected with</a> _stream_.[[storedError]].
  1. Assert: _state_ is `"writable"`.
  1. Let _promise_ be ! WritableStreamAddWriteRequest(_stream_).
  1. Perform ! WritableStreamDefaultControllerWrite(_controller_, _chunk_, _chunkSize_).
  1. Return _promise_.
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="4.7" data-lt="WritableStreamDefaultController" id="ws-default-controller-class"><span class="secno">4.7. </span><span class="content">Class <code>WritableStreamDefaultController</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class④">WritableStreamDefaultController</a></code> class has methods that allow control of a <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①①">WritableStream</a></code>'s state. When
constructing a <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①②">WritableStream</a></code>, the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②⓪">underlying sink</a> is given a corresponding <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class⑤">WritableStreamDefaultController</a></code> instance to manipulate.</p>
   <h4 class="heading settled" data-level="4.7.1" id="ws-default-controller-class-definition"><span class="secno">4.7.1. </span><span class="content">Class definition</span><a class="self-link" href="#ws-default-controller-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class⑥">WritableStreamDefaultController</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>,
it would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> WritableStreamDefaultController <c- p>{</c->
  <a href="#ws-default-controller-constructor" id="ref-for-ws-default-controller-constructor">constructor</a><c- p>()</c-> <c- c1>// always throws</c->

  <a href="#ws-default-controller-error" id="ref-for-ws-default-controller-error">error</a><c- p>(</c->e<c- p>)</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="4.7.2" id="ws-default-controller-internal-slots"><span class="secno">4.7.2. </span><span class="content">Internal slots</span><a class="self-link" href="#ws-default-controller-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class⑦">WritableStreamDefaultController</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[abortAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm, taking one argument (the abort reason), which communicates
      a requested abort to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②①">underlying sink</a> 
     <tr>
      <td>[[closeAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm which communicates a requested close to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②②">underlying
      sink</a> 
     <tr>
      <td>[[controlledWritableStream]] 
      <td class="non-normative">The <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①③">WritableStream</a></code> instance controlled 
     <tr>
      <td>[[queue]] 
      <td class="non-normative">A List representing the stream’s internal queue of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤③">chunks</a> 
     <tr>
      <td>[[queueTotalSize]] 
      <td class="non-normative">The total size of all the chunks stored in [[queue]] (see <a href="#queue-with-sizes">§ 6.2 Queue-with-sizes operations</a>) 
     <tr>
      <td>[[started]] 
      <td class="non-normative">A boolean flag indicating whether the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②③">underlying sink</a> has finished starting 
     <tr>
      <td>[[strategyHWM]] 
      <td class="non-normative">A number supplied by the creator of the stream as part of the stream’s <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy⑤">queuing
      strategy</a>, indicating the point at which the stream will apply <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①③">backpressure</a> to its <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②④">underlying
      sink</a> 
     <tr>
      <td>[[strategySizeAlgorithm]] 
      <td class="non-normative">An algorithm to calculate the size of enqueued <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤④">chunks</a>, as part of the stream’s <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy⑥">queuing strategy</a> 
     <tr>
      <td>[[writeAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm, taking one argument (the <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤⑤">chunk</a> to write), which
      writes data to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②⑤">underlying sink</a> 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultController" data-dfn-type="constructor" data-export data-level="4.7.3" data-lt="WritableStreamDefaultController()" id="ws-default-controller-constructor"><span class="secno">4.7.3. </span><span class="content">new WritableStreamDefaultController()</span></h4>
   <div class="note" role="note"> The <code>WritableStreamDefaultController</code> constructor cannot be used directly; <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class⑧">WritableStreamDefaultController</a></code> instances are created automatically during <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①④">WritableStream</a></code> construction. </div>
    <emu-alg>
  1. Throw a *TypeError* exception.
</emu-alg> 
   <h4 class="heading settled" data-level="4.7.4" id="ws-default-controller-prototype"><span class="secno">4.7.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class⑨">WritableStreamDefaultController</a></code> prototype</span><a class="self-link" href="#ws-default-controller-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="WritableStreamDefaultController" data-dfn-type="method" data-export data-level="4.7.4.1" data-lt="error(e)" id="ws-default-controller-error"><span class="secno">4.7.4.1. </span><span class="content">error(<var>e</var>)</span></h5>
   <div class="note" role="note">
     The <code>error</code> method will error the writable stream, making all future interactions with it fail with the
  given error <code>e</code>. 
    <p>This method is rarely used, since usually it suffices to return a rejected promise from one of the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②⑥">underlying
  sink</a>’s methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
  normal lifecycle of interactions with the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②⑦">underlying sink</a>.</p>
   </div>
    <emu-alg>
  1. If ! IsWritableStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. Let _state_ be *this*.[[controlledWritableStream]].[[state]].
  1. If _state_ is not `"writable"`, return.
  1. Perform ! WritableStreamDefaultControllerError(*this*, _e_).
</emu-alg> 
   <h4 class="heading settled" data-level="4.7.5" id="ws-default-controller-internal-methods"><span class="secno">4.7.5. </span><span class="content">Writable stream default controller internal methods</span><a class="self-link" href="#ws-default-controller-internal-methods"></a></h4>
   <p>The following are additional internal methods implemented by each <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class①⓪">WritableStreamDefaultController</a></code> instance. The
writable stream implementation will call into these.</p>
   <p class="note" role="note">The reason these are in method form, instead of as abstract operations, is to make it clear that the
writable stream implementation is decoupled from the controller implementation, and could in the future be expanded with
other controllers, as long as those controllers implemented such internal methods. A similar scenario is seen for
readable streams, where there actually are multiple controller types and as such the counterpart internal methods are
used polymorphically. </p>
   <h5 class="heading settled" data-level="4.7.5.1" id="ws-default-controller-private-abort"><span class="secno">4.7.5.1. </span><span class="content">[[AbortSteps]]( <var>reason</var> )</span><span id="writable-stream-default-controller-abort"></span><a class="self-link" href="#ws-default-controller-private-abort"></a></h5>
    <emu-alg>
  1. Let _result_ be the result of performing *this*.[[abortAlgorithm]], passing _reason_.
  1. Perform ! WritableStreamDefaultControllerClearAlgorithms(*this*).
  1. Return _result_.
</emu-alg> 
   <h5 class="heading settled" data-level="4.7.5.2" id="ws-default-controller-private-error"><span class="secno">4.7.5.2. </span><span class="content">[[ErrorSteps]]()</span><a class="self-link" href="#ws-default-controller-private-error"></a></h5>
    <emu-alg>
  1. Perform ! ResetQueue(*this*).
</emu-alg> 
   <h3 class="heading settled" data-level="4.8" id="ws-default-controller-abstract-ops"><span class="secno">4.8. </span><span class="content">Writable stream default controller abstract operations</span><a class="self-link" href="#ws-default-controller-abstract-ops"></a></h3>
   <h4 aoid="IsWritableStreamDefaultController" class="heading settled" data-level="4.8.1" id="is-writable-stream-default-controller" nothrow><span class="secno">4.8.1. </span><span class="content">IsWritableStreamDefaultController ( <var>x</var> )</span><a class="self-link" href="#is-writable-stream-default-controller"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have an [[controlledWritableStream]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="SetUpWritableStreamDefaultController" class="heading settled" data-level="4.8.2" id="set-up-writable-stream-default-controller" throws><span class="secno">4.8.2. </span><span class="content">SetUpWritableStreamDefaultController ( <var>stream</var>, <var>controller</var>, <var>startAlgorithm</var>, <var>writeAlgorithm</var>, <var>closeAlgorithm</var>, <var>abortAlgorithm</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span><a class="self-link" href="#set-up-writable-stream-default-controller"></a></h4>
    <emu-alg>
  1. Assert: ! IsWritableStream(_stream_) is *true*.
  1. Assert: _stream_.[[writableStreamController]] is *undefined*.
  1. Set _controller_.[[controlledWritableStream]] to _stream_.
  1. Set _stream_.[[writableStreamController]] to _controller_.
  1. Perform ! ResetQueue(_controller_).
  1. Set _controller_.[[started]] to *false*.
  1. Set _controller_.[[strategySizeAlgorithm]] to _sizeAlgorithm_.
  1. Set _controller_.[[strategyHWM]] to _highWaterMark_.
  1. Set _controller_.[[writeAlgorithm]] to _writeAlgorithm_.
  1. Set _controller_.[[closeAlgorithm]] to _closeAlgorithm_.
  1. Set _controller_.[[abortAlgorithm]] to _abortAlgorithm_.
  1. Let _backpressure_ be ! WritableStreamDefaultControllerGetBackpressure(_controller_).
  1. Perform ! WritableStreamUpdateBackpressure(_stream_, _backpressure_).
  1. Let _startResult_ be the result of performing _startAlgorithm_. (This may throw an exception.)
  1. Let _startPromise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with②⓪">a promise resolved with</a> _startResult_.
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment⑥">Upon fulfillment</a> of _startPromise_,
    1. Assert: _stream_.[[state]] is `"writable"` or `"erroring"`.
    1. Set _controller_.[[started]] to *true*.
    1. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(_controller_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection⑦">Upon rejection</a> of _startPromise_ with reason _r_,
    1. Assert: _stream_.[[state]] is `"writable"` or `"erroring"`.
    1. Set _controller_.[[started]] to *true*.
    1. Perform ! WritableStreamDealWithRejection(_stream_, _r_).
</emu-alg> 
   <h4 aoid="SetUpWritableStreamDefaultControllerFromUnderlyingSink" class="heading settled" data-level="4.8.3" id="set-up-writable-stream-default-controller-from-underlying-sink" throws><span class="secno">4.8.3. </span><span class="content">SetUpWritableStreamDefaultControllerFromUnderlyingSink ( <var>stream</var>, <var>underlyingSink</var>, <var>highWaterMark</var>, <var>sizeAlgorithm</var> )</span><a class="self-link" href="#set-up-writable-stream-default-controller-from-underlying-sink"></a></h4>
    <emu-alg>
  1. Assert: _underlyingSink_ is not *undefined*.
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class①①">WritableStreamDefaultController</a>`'s `prototype`
     property).
  1. Let _startAlgorithm_ be the following steps:
    1. Return ? InvokeOrNoop(_underlyingSink_, `"start"`, « _controller_ »).
  1. Let _writeAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_underlyingSink_, `"write"`, *1*, « _controller_ »).
  1. Let _closeAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_underlyingSink_, `"close"`, *0*, « »).
  1. Let _abortAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_underlyingSink_, `"abort"`, *1*, « »).
  1. Perform ? SetUpWritableStreamDefaultController(_stream_, _controller_, _startAlgorithm_, _writeAlgorithm_,
     _closeAlgorithm_, _abortAlgorithm_, _highWaterMark_, _sizeAlgorithm_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerClearAlgorithms" class="heading settled" data-level="4.8.4" id="writable-stream-default-controller-clear-algorithms" nothrow><span class="secno">4.8.4. </span><span class="content">WritableStreamDefaultControllerClearAlgorithms ( <var>controller</var> )</span><a class="self-link" href="#writable-stream-default-controller-clear-algorithms"></a></h4>
   <p>This abstract operation is called once the stream is closed or errored and the algorithms will not be executed any more.
By removing the algorithm references it permits the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②⑧">underlying sink</a> object to be garbage collected even if the <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①⑤">WritableStream</a></code> itself is still referenced.</p>
   <p class="note" role="note">The results of this algorithm are not currently observable, but could become so if JavaScript eventually
adds <a href="https://github.com/tc39/proposal-weakrefs/">weak references</a>. But even without that factor,
implementations will likely want to include similar steps.</p>
   <p class="note" role="note">This operation will be performed multiple times in some edge cases. After the first time it will do
nothing.</p>
    <emu-alg>
  1. Set _controller_.[[writeAlgorithm]] to *undefined*.
  1. Set _controller_.[[closeAlgorithm]] to *undefined*.
  1. Set _controller_.[[abortAlgorithm]] to *undefined*.
  1. Set _controller_.[[strategySizeAlgorithm]] to *undefined*.
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerClose" class="heading settled" data-level="4.8.5" id="writable-stream-default-controller-close" nothrow><span class="secno">4.8.5. </span><span class="content">WritableStreamDefaultControllerClose ( <var>controller</var> )</span><a class="self-link" href="#writable-stream-default-controller-close"></a></h4>
    <emu-alg>
  1. Perform ! EnqueueValueWithSize(_controller_, `"close"`, *0*).
  1. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(_controller_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerGetChunkSize" class="heading settled" data-level="4.8.6" id="writable-stream-default-controller-get-chunk-size" nothrow><span class="secno">4.8.6. </span><span class="content">WritableStreamDefaultControllerGetChunkSize ( <var>controller</var>, <var>chunk</var> )</span><a class="self-link" href="#writable-stream-default-controller-get-chunk-size"></a></h4>
    <emu-alg>
  1. Let _returnValue_ be the result of performing _controller_.[[strategySizeAlgorithm]], passing in _chunk_, and
     interpreting the result as an ECMAScript completion value.
  1. If _returnValue_ is an abrupt completion,
    1. Perform ! WritableStreamDefaultControllerErrorIfNeeded(_controller_, _returnValue_.[[Value]]).
    1. Return 1.
  1. Return _returnValue_.[[Value]].
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerGetDesiredSize" class="heading settled" data-level="4.8.7" id="writable-stream-default-controller-get-desired-size" nothrow><span class="secno">4.8.7. </span><span class="content">WritableStreamDefaultControllerGetDesiredSize ( <var>controller</var> )</span><a class="self-link" href="#writable-stream-default-controller-get-desired-size"></a></h4>
    <emu-alg>
  1. Return _controller_.[[strategyHWM]] − _controller_.[[queueTotalSize]].
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerWrite" class="heading settled" data-level="4.8.8" id="writable-stream-default-controller-write" nothrow><span class="secno">4.8.8. </span><span class="content">WritableStreamDefaultControllerWrite ( <var>controller</var>, <var>chunk</var>, <var>chunkSize</var> )</span><a class="self-link" href="#writable-stream-default-controller-write"></a></h4>
    <emu-alg>
  1. Let _writeRecord_ be Record {[[chunk]]: _chunk_}.
  1. Let _enqueueResult_ be EnqueueValueWithSize(_controller_, _writeRecord_, _chunkSize_).
  1. If _enqueueResult_ is an abrupt completion,
    1. Perform ! WritableStreamDefaultControllerErrorIfNeeded(_controller_, _enqueueResult_.[[Value]]).
    1. Return.
  1. Let _stream_ be _controller_.[[controlledWritableStream]].
  1. If ! WritableStreamCloseQueuedOrInFlight(_stream_) is *false* and _stream_.[[state]] is `"writable"`,
    1. Let _backpressure_ be ! WritableStreamDefaultControllerGetBackpressure(_controller_).
    1. Perform ! WritableStreamUpdateBackpressure(_stream_, _backpressure_).
  1. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(_controller_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerAdvanceQueueIfNeeded" class="heading settled" data-level="4.8.9" id="writable-stream-default-controller-advance-queue-if-needed" nothrow><span class="secno">4.8.9. </span><span class="content">WritableStreamDefaultControllerAdvanceQueueIfNeeded ( <var>controller</var> )</span><a class="self-link" href="#writable-stream-default-controller-advance-queue-if-needed"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledWritableStream]].
  1. If _controller_.[[started]] is *false*, return.
  1. If _stream_.[[inFlightWriteRequest]] is not *undefined*, return.
  1. Let _state_ be _stream_.[[state]].
  1. Assert: _state_ is not `"closed"` or `"errored"`.
  1. If _state_ is `"erroring"`,
    1. Perform ! WritableStreamFinishErroring(_stream_).
    1. Return.
  1. If _controller_.[[queue]] is empty, return.
  1. Let _writeRecord_ be ! PeekQueueValue(_controller_).
  1. If _writeRecord_ is `"close"`, perform ! WritableStreamDefaultControllerProcessClose(_controller_).
  1. Otherwise, perform ! WritableStreamDefaultControllerProcessWrite(_controller_, _writeRecord_.[[chunk]]).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerErrorIfNeeded" class="heading settled" data-level="4.8.10" id="writable-stream-default-controller-error-if-needed" nothrow><span class="secno">4.8.10. </span><span class="content">WritableStreamDefaultControllerErrorIfNeeded ( <var>controller</var>, <var>error</var> )</span><a class="self-link" href="#writable-stream-default-controller-error-if-needed"></a></h4>
    <emu-alg>
  1. If _controller_.[[controlledWritableStream]].[[state]] is `"writable"`, perform !
     WritableStreamDefaultControllerError(_controller_, _error_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerProcessClose" class="heading settled" data-level="4.8.11" id="writable-stream-default-controller-process-close" nothrow><span class="secno">4.8.11. </span><span class="content">WritableStreamDefaultControllerProcessClose ( <var>controller</var> )</span><a class="self-link" href="#writable-stream-default-controller-process-close"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledWritableStream]].
  1. Perform ! WritableStreamMarkCloseRequestInFlight(_stream_).
  1. Perform ! DequeueValue(_controller_).
  1. Assert: _controller_.[[queue]] is empty.
  1. Let _sinkClosePromise_ be the result of performing _controller_.[[closeAlgorithm]].
  1. Perform ! WritableStreamDefaultControllerClearAlgorithms(_controller_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment⑦">Upon fulfillment</a> of _sinkClosePromise_,
    1. Perform ! WritableStreamFinishInFlightClose(_stream_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection⑧">Upon rejection</a> of _sinkClosePromise_ with reason _reason_,
    1. Perform ! WritableStreamFinishInFlightCloseWithError(_stream_, _reason_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerProcessWrite" class="heading settled" data-level="4.8.12" id="writable-stream-default-controller-process-write" nothrow><span class="secno">4.8.12. </span><span class="content">WritableStreamDefaultControllerProcessWrite ( <var>controller</var>, <var>chunk</var> )</span><a class="self-link" href="#writable-stream-default-controller-process-write"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledWritableStream]].
  1. Perform ! WritableStreamMarkFirstWriteRequestInFlight(_stream_).
  1. Let _sinkWritePromise_ be the result of performing _controller_.[[writeAlgorithm]], passing in _chunk_.
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment" id="ref-for-upon-fulfillment⑧">Upon fulfillment</a> of _sinkWritePromise_,
    1. Perform ! WritableStreamFinishInFlightWrite(_stream_).
    1. Let _state_ be _stream_.[[state]].
    1. Assert: _state_ is `"writable"` or `"erroring"`.
    1. Perform ! DequeueValue(_controller_).
    1. If ! WritableStreamCloseQueuedOrInFlight(_stream_) is *false* and _state_ is `"writable"`,
      1. Let _backpressure_ be ! WritableStreamDefaultControllerGetBackpressure(_controller_).
      1. Perform ! WritableStreamUpdateBackpressure(_stream_, _backpressure_).
    1. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(_controller_).
  1. <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection" id="ref-for-upon-rejection⑨">Upon rejection</a> of _sinkWritePromise_ with _reason_,
    1. If _stream_.[[state]] is `"writable"`, perform ! WritableStreamDefaultControllerClearAlgorithms(_controller_).
    1. Perform ! WritableStreamFinishInFlightWriteWithError(_stream_, _reason_).
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerGetBackpressure" class="heading settled" data-level="4.8.13" id="writable-stream-default-controller-get-backpressure" nothrow><span class="secno">4.8.13. </span><span class="content">WritableStreamDefaultControllerGetBackpressure ( <var>controller</var> )</span><a class="self-link" href="#writable-stream-default-controller-get-backpressure"></a></h4>
    <emu-alg>
  1. Let _desiredSize_ be ! WritableStreamDefaultControllerGetDesiredSize(_controller_).
  1. Return _desiredSize_ ≤ *0*.
</emu-alg> 
   <h4 aoid="WritableStreamDefaultControllerError" class="heading settled" data-level="4.8.14" id="writable-stream-default-controller-error" nothrow><span class="secno">4.8.14. </span><span class="content">WritableStreamDefaultControllerError ( <var>controller</var>, <var>error</var> )</span><a class="self-link" href="#writable-stream-default-controller-error"></a></h4>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledWritableStream]].
  1. Assert: _stream_.[[state]] is `"writable"`.
  1. Perform ! WritableStreamDefaultControllerClearAlgorithms(_controller_).
  1. Perform ! WritableStreamStartErroring(_stream_, _error_).
</emu-alg> 
   <h2 class="heading settled" data-level="5" id="ts"><span class="secno">5. </span><span class="content">Transform streams</span><a class="self-link" href="#ts"></a></h2>
   <h3 class="heading settled" data-level="5.1" id="ts-intro"><span class="secno">5.1. </span><span class="content">Using transform streams</span><a class="self-link" href="#ts-intro"></a></h3>
   <div class="example" id="example-basic-pipe-through">
    <a class="self-link" href="#example-basic-pipe-through"></a> The natural way to use a transform stream is to place it in a <a data-link-type="dfn" href="#piping" id="ref-for-piping①⓪">pipe</a> between a <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①③">readable stream</a> and a <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①②">writable stream</a>. <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤⑥">Chunks</a> that travel from the <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①④">readable stream</a> to the <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①③">writable stream</a> will be transformed as they pass through the transform stream. <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①④">Backpressure</a> is respected, so data will not be
  read faster than it can be transformed and consumed. 
<pre><code class="lang-javascript highlight">readableStream
  <c- p>.</c->pipeThrough<c- p>(</c->transformStream<c- p>)</c->
  <c- p>.</c->pipeTo<c- p>(</c->writableStream<c- p>)</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"All data successfully transformed!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Something went wrong!"</c-><c- p>,</c-> e<c- p>));</c->
</code></pre>
   </div>
   <div class="example" id="example-transform-stream-properties">
    <a class="self-link" href="#example-transform-stream-properties"></a> You can also use the <code class="idl"><a data-link-type="idl" href="#ts-readable" id="ref-for-ts-readable">readable</a></code> and <code class="idl"><a data-link-type="idl" href="#ts-writable" id="ref-for-ts-writable">writable</a></code> properties of a transform stream
  directly to access the usual interfaces of a <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①⑤">readable stream</a> and <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①④">writable stream</a>. In this example we
  supply data to the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side①">writable side</a> of the stream using its <a data-link-type="dfn" href="#writer" id="ref-for-writer⑤">writer</a> interface. The <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side①">readable side</a> is
  then piped to <code>anotherWritableStream</code>. 
<pre><code class="lang-javascript highlight"><c- kr>const</c-> writer <c- o>=</c-> transformStream<c- p>.</c->writable<c- p>.</c->getWriter<c- p>();</c->
writer<c- p>.</c->write<c- p>(</c-><c- u>"input chunk"</c-><c- p>);</c->
transformStream<c- p>.</c->readable<c- p>.</c->pipeTo<c- p>(</c->anotherWritableStream<c- p>);</c->
</code></pre>
   </div>
   <div class="example" id="example-transform-identity">
    <a class="self-link" href="#example-transform-identity"></a> One use of <a data-link-type="dfn" href="#identity-transform-stream" id="ref-for-identity-transform-stream">identity transform streams</a> is to easily convert between readable and writable streams. For example,
  the <code class="idl"><a data-link-type="idl" href="https://fetch.spec.whatwg.org/#dom-global-fetch" id="ref-for-dom-global-fetch">fetch()</a></code> API accepts a readable stream <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-body" id="ref-for-concept-request-body">request body</a>, but it can be more
  convenient to write data for uploading via a writable stream interface. Using an identity transform stream addresses
  this: 
<pre><code class="lang-javascript highlight"><c- kr>const</c-> <c- p>{</c-> writable<c- p>,</c-> readable <c- p>}</c-> <c- o>=</c-> <c- k>new</c-> TransformStream<c- p>();</c->
fetch<c- p>(</c-><c- u>"..."</c-><c- p>,</c-> <c- p>{</c-> body<c- o>:</c-> readable <c- p>}).</c->then<c- p>(</c->response <c- p>=></c-> <c- d>/* ... */</c-><c- p>);</c->

<c- kr>const</c-> writer <c- o>=</c-> writable<c- p>.</c->getWriter<c- p>();</c->
writer<c- p>.</c->write<c- p>(</c-><c- k>new</c-> Uint8Array<c- p>([</c-><c- mh>0x73</c-><c- p>,</c-> <c- mh>0x74</c-><c- p>,</c-> <c- mh>0x72</c-><c- p>,</c-> <c- mh>0x65</c-><c- p>,</c-> <c- mh>0x61</c-><c- p>,</c-> <c- mh>0x6D</c-><c- p>,</c-> <c- mh>0x73</c-><c- p>,</c-> <c- mh>0x21</c-><c- p>]));</c->
writer<c- p>.</c->close<c- p>();</c->
</code></pre>
    <p>Another use of identity transform streams is to add additional buffering to a <a data-link-type="dfn" href="#piping" id="ref-for-piping①①">pipe</a>. In this example we add
  extra buffering between <code>readableStream</code> and <code>writableStream</code>.</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> writableStrategy <c- o>=</c-> <c- k>new</c-> ByteLengthQueuingStrategy<c- p>({</c-> highWaterMark<c- o>:</c-> <c- mi>1024</c-> <c- o>*</c-> <c- mi>1024</c-> <c- p>});</c->

readableStream
  <c- p>.</c->pipeThrough<c- p>(</c-><c- k>new</c-> TransformStream<c- p>(</c-><c- kc>undefined</c-><c- p>,</c-> writableStrategy<c- p>))</c->
  <c- p>.</c->pipeTo<c- p>(</c->writableStream<c- p>);</c->
</code></pre>
   </div>
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="5.2" data-lt="TransformStream" id="ts-class"><span class="secno">5.2. </span><span class="content">Class <code>TransformStream</code></span></h3>
   <h4 class="heading settled" data-level="5.2.1" id="ts-class-definition"><span class="secno">5.2.1. </span><span class="content">Class definition</span><a class="self-link" href="#ts-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class②">TransformStream</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it would look
like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> TransformStream <c- p>{</c->
  <a href="#ts-constructor" id="ref-for-ts-constructor④">constructor</a><c- p>(</c-><a href="#transformer-api">transformer</a> <c- o>=</c-> <c- p>{},</c-> <a href="#qs-api">writableStrategy</a> <c- o>=</c-> <c- p>{},</c-> <a href="#qs-api">readableStrategy</a> <c- o>=</c-> <c- p>{})</c->

  get <a href="#ts-readable" id="ref-for-ts-readable①">readable</a><c- p>()</c->
  get <a href="#ts-writable" id="ref-for-ts-writable①">writable</a><c- p>()</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="5.2.2" id="ts-internal-slots"><span class="secno">5.2.2. </span><span class="content">Internal slots</span><a class="self-link" href="#ts-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class③">TransformStream</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[backpressure]] 
      <td class="non-normative">Whether there was backpressure on [[readable]] the last time it was observed 
     <tr>
      <td>[[backpressureChangePromise]] 
      <td class="non-normative">A promise which is fulfilled and replaced every time the value of [[backpressure]]
    changes 
     <tr>
      <td>[[readable]] 
      <td class="non-normative">The <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③③">ReadableStream</a></code> instance controlled by this object 
     <tr>
      <td>[[transformStreamController]] 
      <td class="non-normative">A <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class">TransformStreamDefaultController</a></code> created with the ability to control [[readable]]
    and [[writable]]; also used for the <a href="#is-transform-stream">IsTransformStream</a> brand check 
     <tr>
      <td>[[writable]] 
      <td class="non-normative">The <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①⑥">WritableStream</a></code> instance controlled by this object 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStream" data-dfn-type="constructor" data-export data-level="5.2.3" data-lt="TransformStream(transformer, writableStrategy,
readableStrategy)" id="ts-constructor"><span class="secno">5.2.3. </span><span class="content">new TransformStream(<var>transformer</var> = {}, <var>writableStrategy</var> = {}, <var>readableStrategy</var> = {})</span></h4>
   <div class="note" role="note">
     The <code>transformer</code> argument represents the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer①">transformer</a>, as described in <a href="#transformer-api">§ 5.2.4 Transformer API</a>. 
    <p>The <code>writableStrategy</code> and <code>readableStrategy</code> arguments are the <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy⑦">queuing strategy</a> objects
  for the writable and readable sides respectively. These are used in the construction of the <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①⑦">WritableStream</a></code> and <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③④">ReadableStream</a></code> objects and can be used to add buffering to a <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class④">TransformStream</a></code>, in order to smooth out
  variations in the speed of the transformation, or to increase the amount of buffering in a <a data-link-type="dfn" href="#piping" id="ref-for-piping①②">pipe</a>. If they are
  not provided, the default behavior will be the same as a <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class③">CountQueuingStrategy</a></code>, with respective <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark⑤">high water
  marks</a> of 1 and 0.</p>
   </div>
    <emu-alg>
  1. Let _writableSizeFunction_ be ? GetV(_writableStrategy_, `"size"`).
  1. Let _writableHighWaterMark_ be ? GetV(_writableStrategy_, `"highWaterMark"`).
  1. Let _readableSizeFunction_ be ? GetV(_readableStrategy_, `"size"`).
  1. Let _readableHighWaterMark_ be ? GetV(_readableStrategy_, `"highWaterMark"`).
  1. Let _writableType_ be ? GetV(_transformer_, `"writableType"`).
  1. If _writableType_ is not *undefined*, throw a *RangeError* exception.
  1. Let _writableSizeAlgorithm_ be ? MakeSizeAlgorithmFromSizeFunction(_writableSizeFunction_).
  1. If _writableHighWaterMark_ is *undefined*, set _writableHighWaterMark_ to *1*.
  1. Set _writableHighWaterMark_ to ? ValidateAndNormalizeHighWaterMark(_writableHighWaterMark_).
  1. Let _readableType_ be ? GetV(_transformer_, `"readableType"`).
  1. If _readableType_ is not *undefined*, throw a *RangeError* exception.
  1. Let _readableSizeAlgorithm_ be ? MakeSizeAlgorithmFromSizeFunction(_readableSizeFunction_).
  1. If _readableHighWaterMark_ is *undefined*, set _readableHighWaterMark_ to *0*.
  1. Set _readableHighWaterMark_ be ? ValidateAndNormalizeHighWaterMark(_readableHighWaterMark_).
  1. Let _startPromise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise①②">a new promise</a>.
  1. Perform ! InitializeTransformStream(*this*, _startPromise_, _writableHighWaterMark_, _writableSizeAlgorithm_,
     _readableHighWaterMark_, _readableSizeAlgorithm_).
  1. Perform ? SetUpTransformStreamDefaultControllerFromTransformer(*this*, _transformer_).
  1. Let _startResult_ be ? InvokeOrNoop(_transformer_, `"start"`, « *this*.[[transformStreamController]] »).
  1. <a data-link-type="dfn">Resolve</a> _startPromise_ with _startResult_.
</emu-alg> 
   <h4 class="heading settled" data-level="5.2.4" id="transformer-api"><span class="secno">5.2.4. </span><span class="content">Transformer API</span><a class="self-link" href="#transformer-api"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>The <code class="idl"><a data-link-type="idl" href="#ts-constructor" id="ref-for-ts-constructor①">TransformStream()</a></code> constructor accepts as its first argument a JavaScript object representing the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer②">transformer</a>. Such objects can contain any of the following methods:</p>
    <dl>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="transformer" data-dfn-type="method" data-export id="dom-transformer-start"><code>start(<var>controller</var>)</code></dfn>
     <dd>
      <p>A function that is called immediately during creation of the <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class⑤">TransformStream</a></code>.</p>
      <p>Typically this is used to enqueue prefix <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤⑦">chunks</a>, using <code class="idl"><a data-link-type="idl" href="#ts-default-controller-enqueue" id="ref-for-ts-default-controller-enqueue">controller.enqueue()</a></code>. Those chunks will be read from the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side②">readable
    side</a> but don’t depend on any writes to the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side②">writable side</a>.</p>
      <p>If this initial process is asynchronous, for example because it takes some effort to acquire the prefix
    chunks, the function can return a promise to signal success or failure; a rejected promise will error the stream.
    Any thrown exceptions will be re-thrown by the <code class="idl"><a data-link-type="idl" href="#ts-constructor" id="ref-for-ts-constructor②">TransformStream()</a></code> constructor.</p>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="transformer" data-dfn-type="method" data-export id="dom-transformer-transform"><code>transform(<var>chunk</var>, <var>controller</var>)</code></dfn>
     <dd>
      <p>A function called when a new <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤⑧">chunk</a> originally written to the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side③">writable side</a> is ready to be
    transformed. The stream implementation guarantees that this function will be called only after previous transforms
    have succeeded, and never before <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-start" id="ref-for-dom-underlying-sink-start②">start()</a></code> has completed or after <code class="idl"><a data-link-type="idl" href="#dom-transformer-flush" id="ref-for-dom-transformer-flush">flush()</a></code> has been
    called.</p>
      <p>This function performs the actual transformation work of the transform stream. It can enqueue the results using <code class="idl"><a data-link-type="idl" href="#ts-default-controller-enqueue" id="ref-for-ts-default-controller-enqueue①">controller.enqueue()</a></code>. This permits a single chunk written to the
    writable side to result in zero or multiple chunks on the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side③">readable side</a>, depending on how many times <code class="idl"><a data-link-type="idl" href="#ts-default-controller-enqueue" id="ref-for-ts-default-controller-enqueue②">controller.enqueue()</a></code> is called. <a href="#example-ts-lipfuzz">§ 8.9 A transform stream that replaces template tags</a> demonstrates
    this by sometimes enqueuing zero chunks.</p>
      <p>If the process of transforming is asynchronous, this function can return a promise to signal success or failure
    of the transformation. A rejected promise will error both the readable and writable sides of the transform
    stream.</p>
      <p>If no <code class="idl"><a data-link-type="idl" href="#dom-transformer-transform" id="ref-for-dom-transformer-transform①">transform()</a></code> is supplied, the identity transform is used, which enqueues chunks unchanged
    from the writable side to the readable side.</p>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="transformer" data-dfn-type="method" data-export id="dom-transformer-flush"><code>flush(<var>controller</var>)</code></dfn>
     <dd>
      <p>A function called after all <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑤⑨">chunks</a> written to the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side④">writable side</a> have been transformed by
    successfully passing through <code class="idl"><a data-link-type="idl" href="#dom-transformer-transform" id="ref-for-dom-transformer-transform②">transform()</a></code>, and the writable side is about to be closed.</p>
      <p>Typically this is used to enqueue suffix chunks to the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side④">readable side</a>, before that too becomes closed. An
    example can be seen in <a href="#example-ts-lipfuzz">§ 8.9 A transform stream that replaces template tags</a>.</p>
      <p>If the flushing process is asynchronous, the function can return a promise to signal success or failure; the
    result will be communicated to the caller of <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write①①">stream.writable.write()</a></code>.
    Additionally, a rejected promise will error both the readable and writable sides of the stream. Throwing an
    exception is treated the same as returning a rejected promise.</p>
      <p>(Note that there is no need to call <code class="idl"><a data-link-type="idl" href="#ts-default-controller-terminate" id="ref-for-ts-default-controller-terminate">controller.terminate()</a></code> inside <code class="idl"><a data-link-type="idl" href="#dom-transformer-flush" id="ref-for-dom-transformer-flush①">flush()</a></code>; the stream is already in the process of successfully closing down, and terminating
    it would be counterproductive.)</p>
    </dl>
    <p>The <code>controller</code> object passed to <code class="idl"><a data-link-type="idl" href="#dom-transformer-start" id="ref-for-dom-transformer-start">start()</a></code>, <code class="idl"><a data-link-type="idl" href="#dom-transformer-transform" id="ref-for-dom-transformer-transform③">transform()</a></code>, and <code class="idl"><a data-link-type="idl" href="#dom-transformer-flush" id="ref-for-dom-transformer-flush②">flush()</a></code> is an instance of <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class①">TransformStreamDefaultController</a></code>, and has the ability to enqueue <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥⓪">chunks</a> to the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side⑤">readable side</a>, or to terminate or error the stream.</p>
   </div>
   <h4 class="heading settled" data-level="5.2.5" id="ts-prototype"><span class="secno">5.2.5. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class⑥">TransformStream</a></code> prototype</span><a class="self-link" href="#ts-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStream" data-dfn-type="attribute" data-export data-level="5.2.5.1" data-lt="readable" id="ts-readable"><span class="secno">5.2.5.1. </span><span class="content">get readable</span></h5>
   <div class="note" role="note"> The <code>readable</code> getter gives access to the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side⑥">readable side</a> of the transform stream. </div>
    <emu-alg>
  1. If ! IsTransformStream(*this*) is *false*, throw a *TypeError* exception.
  1. Return *this*.[[readable]].
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStream" data-dfn-type="attribute" data-export data-level="5.2.5.2" data-lt="writable" id="ts-writable"><span class="secno">5.2.5.2. </span><span class="content">get writable</span></h5>
   <div class="note" role="note"> The <code>writable</code> getter gives access to the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side⑤">writable side</a> of the transform stream. </div>
    <emu-alg>
  1. If ! IsTransformStream(*this*) is *false*, throw a *TypeError* exception.
  1. Return *this*.[[writable]].
</emu-alg> 
   <h3 class="heading settled" data-level="5.3" id="ts-abstract-ops"><span class="secno">5.3. </span><span class="content">General transform stream abstract operations</span><a class="self-link" href="#ts-abstract-ops"></a></h3>
   <h4 aoid="CreateTransformStream" class="heading settled" data-export data-level="5.3.1" id="create-transform-stream" throws><span class="secno">5.3.1. </span><span class="content">CreateTransformStream ( <var>startAlgorithm</var>, <var>transformAlgorithm</var>, <var>flushAlgorithm</var> [, <var>writableHighWaterMark</var> [, <var>writableSizeAlgorithm</var> [, <var>readableHighWaterMark</var> [, <var>readableSizeAlgorithm</var> ] ] ] ] )</span><a class="self-link" href="#create-transform-stream"></a></h4>
   <p>This abstract operation is meant to be called from other specifications that wish to create <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class⑦">TransformStream</a></code> instances. The <var>transformAlgorithm</var> and <var>flushAlgorithm</var> algorithms must return promises; if supplied, <var>writableHighWaterMark</var> and <var>readableHighWaterMark</var> must be non-negative, non-NaN numbers; and if
supplied, <var>writableSizeAlgorithm</var> and <var>readableSizeAlgorithm</var> must be algorithms accepting <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥①">chunk</a> objects and returning numbers.</p>
   <p class="note" role="note">CreateTransformStream throws an exception if and only if the supplied <var>startAlgorithm</var> throws.</p>
    <emu-alg>
  1. If _writableHighWaterMark_ was not passed, set it to *1*.
  1. If _writableSizeAlgorithm_ was not passed, set it to an algorithm that returns *1*.
  1. If _readableHighWaterMark_ was not passed, set it to *0*.
  1. If _readableSizeAlgorithm_ was not passed, set it to an algorithm that returns *1*.
  1. Assert: ! IsNonNegativeNumber(_writableHighWaterMark_) is *true*.
  1. Assert: ! IsNonNegativeNumber(_readableHighWaterMark_) is *true*.
  1. Let _stream_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#ts-class" id="ref-for-ts-class⑧">TransformStream</a>`'s `prototype` property).
  1. Let _startPromise_ be <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise①③">a new promise</a>.
  1. Perform ! InitializeTransformStream(_stream_, _startPromise_, _writableHighWaterMark_, _writableSizeAlgorithm_,
     _readableHighWaterMark_, _readableSizeAlgorithm_).
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class②">TransformStreamDefaultController</a>`'s `prototype`
     property).
  1. Perform ! SetUpTransformStreamDefaultController(_stream_, _controller_, _transformAlgorithm_, _flushAlgorithm_).
  1. Let _startResult_ be the result of performing _startAlgorithm_. (This may throw an exception.)
  1. <a data-link-type="dfn">Resolve</a> _startPromise_ with _startResult_.
  1. Return _stream_.
</emu-alg> 
   <h4 aoid="InitializeTransformStream" class="heading settled" data-level="5.3.2" id="initialize-transform-stream" nothrow><span class="secno">5.3.2. </span><span class="content">InitializeTransformStream ( <var>stream</var>, <var>startPromise</var>, <var>writableHighWaterMark</var>, <var>writableSizeAlgorithm</var>, <var>readableHighWaterMark</var>, <var>readableSizeAlgorithm</var> )</span><a class="self-link" href="#initialize-transform-stream"></a></h4>
    <emu-alg>
  1. Let _startAlgorithm_ be an algorithm that returns _startPromise_.
  1. Let _writeAlgorithm_ be the following steps, taking a _chunk_ argument:
    1. Return ! TransformStreamDefaultSinkWriteAlgorithm(_stream_, _chunk_).
  1. Let _abortAlgorithm_ be the following steps, taking a _reason_ argument:
    1. Return ! TransformStreamDefaultSinkAbortAlgorithm(_stream_, _reason_).
  1. Let _closeAlgorithm_ be the following steps:
    1. Return ! TransformStreamDefaultSinkCloseAlgorithm(_stream_).
  1. Set _stream_.[[writable]] to ! CreateWritableStream(_startAlgorithm_, _writeAlgorithm_, _closeAlgorithm_,
     _abortAlgorithm_, _writableHighWaterMark_, _writableSizeAlgorithm_).
  1. Let _pullAlgorithm_ be the following steps:
    1. Return ! TransformStreamDefaultSourcePullAlgorithm(_stream_).
  1. Let _cancelAlgorithm_ be the following steps, taking a _reason_ argument:
    1. Perform ! TransformStreamErrorWritableAndUnblockWrite(_stream_, _reason_).
    1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with②①">a promise resolved with</a> *undefined*.
  1. Set _stream_.[[readable]] to ! CreateReadableStream(_startAlgorithm_, _pullAlgorithm_, _cancelAlgorithm_,
     _readableHighWaterMark_, _readableSizeAlgorithm_).
  1. Set _stream_.[[backpressure]] and _stream_.[[backpressureChangePromise]] to *undefined*.
     <p class="note" role="note">The [[backpressure]] slot is set to *undefined* so that it can be initialized by
     TransformStreamSetBackpressure. Alternatively, implementations can use a strictly boolean value for
     [[backpressure]] and change the way it is initialized. This will not be visible to user code so long as the
     initialization is correctly completed before _transformer_’s <code class="idl"><a data-link-type="idl" href="#dom-transformer-start" id="ref-for-dom-transformer-start①">start()</a></code> method is called.</p>
  1. Perform ! TransformStreamSetBackpressure(_stream_, *true*).
  1. Set _stream_.[[transformStreamController]] to *undefined*.
</emu-alg> 
   <h4 aoid="IsTransformStream" class="heading settled" data-level="5.3.3" id="is-transform-stream" nothrow><span class="secno">5.3.3. </span><span class="content">IsTransformStream ( <var>x</var> )</span><a class="self-link" href="#is-transform-stream"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have a [[transformStreamController]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="TransformStreamError" class="heading settled" data-level="5.3.4" id="transform-stream-error" nothrow><span class="secno">5.3.4. </span><span class="content">TransformStreamError ( <var>stream</var>, <var>e</var> )</span><a class="self-link" href="#transform-stream-error"></a></h4>
    <emu-alg>
  1. Perform ! ReadableStreamDefaultControllerError(_stream_.[[readable]].[[readableStreamController]], _e_).
  1. Perform ! TransformStreamErrorWritableAndUnblockWrite(_stream_, _e_).
</emu-alg> 
   <p class="note" role="note">This operation works correctly when one or both sides are already errored. As a result, calling
algorithms do not need to check stream states when responding to an error condition.</p>
   <h4 aoid="TransformStreamErrorWritableAndUnblockWrite" class="heading settled" data-level="5.3.5" id="transform-stream-error-writable-and-unblock-write" nothrow><span class="secno">5.3.5. </span><span class="content">TransformStreamErrorWritableAndUnblockWrite ( <var>stream</var>, <var>e</var> )</span><a class="self-link" href="#transform-stream-error-writable-and-unblock-write"></a></h4>
    <emu-alg>
  1. Perform ! TransformStreamDefaultControllerClearAlgorithms(_stream_.[[transformStreamController]]).
  1. Perform ! WritableStreamDefaultControllerErrorIfNeeded(_stream_.[[writable]].[[writableStreamController]], _e_).
  1. If _stream_.[[backpressure]] is *true*, perform ! TransformStreamSetBackpressure(_stream_, *false*).
</emu-alg> 
   <p class="note" role="note">The TransformStreamDefaultSinkWriteAlgorithm abstract operation could be waiting for the promise
stored in the [[backpressureChangePromise]] slot to resolve. This call to TransformStreamSetBackpressure ensures that
the promise always resolves.</p>
   <h4 aoid="TransformStreamSetBackpressure" class="heading settled" data-level="5.3.6" id="transform-stream-set-backpressure" nothrow><span class="secno">5.3.6. </span><span class="content">TransformStreamSetBackpressure
( <var>stream</var>, <var>backpressure</var> )</span><a class="self-link" href="#transform-stream-set-backpressure"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[backpressure]] is not _backpressure_.
  1. If _stream_.[[backpressureChangePromise]] is not *undefined*, <a data-link-type="dfn">resolve</a>
     stream.[[backpressureChangePromise]] with *undefined*.
  1. Set _stream_.[[backpressureChangePromise]] to <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise" id="ref-for-a-new-promise①④">a new promise</a>.
  1. Set _stream_.[[backpressure]] to _backpressure_.
</emu-alg> 
   <h3 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="5.4" data-lt="TransformStreamDefaultController" id="ts-default-controller-class"><span class="secno">5.4. </span><span class="content">Class <code>TransformStreamDefaultController</code></span></h3>
   <p>The <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class③">TransformStreamDefaultController</a></code> class has methods that allow manipulation of the associated <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③⑤">ReadableStream</a></code> and <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①⑧">WritableStream</a></code>. When constructing a <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class⑨">TransformStream</a></code>, the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer③">transformer</a> object is given a corresponding <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class④">TransformStreamDefaultController</a></code> instance to manipulate.</p>
   <h4 class="heading settled" data-level="5.4.1" id="ts-default-controller-class-definition"><span class="secno">5.4.1. </span><span class="content">Class definition</span><a class="self-link" href="#ts-default-controller-class-definition"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class⑤">TransformStreamDefaultController</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>,
it would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> TransformStreamDefaultController <c- p>{</c->
  <a href="#ts-default-controller-constructor" id="ref-for-ts-default-controller-constructor">constructor</a><c- p>()</c-> <c- c1>// always throws</c->

  get <a href="#ts-default-controller-desired-size" id="ref-for-ts-default-controller-desired-size">desiredSize</a><c- p>()</c->

  <a href="#ts-default-controller-enqueue" id="ref-for-ts-default-controller-enqueue③">enqueue</a><c- p>(</c->chunk<c- p>)</c->
  <a href="#ts-default-controller-error" id="ref-for-ts-default-controller-error">error</a><c- p>(</c->reason<c- p>)</c->
  <a href="#ts-default-controller-terminate" id="ref-for-ts-default-controller-terminate①">terminate</a><c- p>()</c->
<c- p>}</c->
</code></pre>
   </div>
   <h4 class="heading settled" data-level="5.4.2" id="ts-default-controller-internal-slots"><span class="secno">5.4.2. </span><span class="content">Internal slots</span><a class="self-link" href="#ts-default-controller-internal-slots"></a></h4>
   <p>Instances of <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class⑥">TransformStreamDefaultController</a></code> are created with the internal slots described in the following table:</p>
   <table>
    <thead>
     <tr>
      <th>Internal Slot
      <th>Description (<em>non-normative</em>)
    <tbody>
     <tr>
      <td>[[controlledTransformStream]] 
      <td class="non-normative">The <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①⓪">TransformStream</a></code> instance controlled; also used for the
      IsTransformStreamDefaultController brand check 
     <tr>
      <td>[[flushAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm which communicates a requested close to the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer④">transformer</a> 
     <tr>
      <td>[[transformAlgorithm]] 
      <td class="non-normative">A promise-returning algorithm, taking one argument (the <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥②">chunk</a> to transform), which
      requests the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer⑤">transformer</a> perform its transformation 
   </table>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStreamDefaultController" data-dfn-type="constructor" data-export data-level="5.4.3" data-lt="TransformStreamDefaultController()" id="ts-default-controller-constructor"><span class="secno">5.4.3. </span><span class="content">new TransformStreamDefaultController()</span></h4>
   <div class="note" role="note"> The <code>TransformStreamDefaultController</code> constructor cannot be used directly; <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class⑦">TransformStreamDefaultController</a></code> instances are created automatically during <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①①">TransformStream</a></code> construction. </div>
    <emu-alg>
  1. Throw a *TypeError* exception.
</emu-alg> 
   <h4 class="heading settled" data-level="5.4.4" id="ts-default-controller-prototype"><span class="secno">5.4.4. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class⑧">TransformStreamDefaultController</a></code> prototype</span><a class="self-link" href="#ts-default-controller-prototype"></a></h4>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStreamDefaultController" data-dfn-type="attribute" data-export data-level="5.4.4.1" data-lt="desiredSize" id="ts-default-controller-desired-size"><span class="secno">5.4.4.1. </span><span class="content">get
desiredSize</span></h5>
   <div class="note" role="note"> The <code>desiredSize</code> getter returns the <a data-link-type="dfn" href="#desired-size-to-fill-a-streams-internal-queue" id="ref-for-desired-size-to-fill-a-streams-internal-queue①⓪">desired size
  to fill the readable side’s internal queue</a>. It can be negative, if the queue is over-full. </div>
    <emu-alg>
  1. If ! IsTransformStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. Let _readableController_ be *this*.[[controlledTransformStream]].[[readable]].[[readableStreamController]].
  1. Return ! ReadableStreamDefaultControllerGetDesiredSize(_readableController_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStreamDefaultController" data-dfn-type="method" data-export data-level="5.4.4.2" data-lt="enqueue(chunk)" id="ts-default-controller-enqueue"><span class="secno">5.4.4.2. </span><span class="content">enqueue(<var>chunk</var>)</span></h5>
   <div class="note" role="note"> The <code>enqueue</code> method will enqueue a given <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥③">chunk</a> in the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side⑦">readable side</a>. </div>
    <emu-alg>
  1. If ! IsTransformStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. Perform ? TransformStreamDefaultControllerEnqueue(*this*, _chunk_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStreamDefaultController" data-dfn-type="method" data-export data-level="5.4.4.3" data-lt="error(reason)" id="ts-default-controller-error"><span class="secno">5.4.4.3. </span><span class="content">error(<var>reason</var>)</span></h5>
   <div class="note" role="note"> The <code>error</code> method will error both the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side⑧">readable side</a> and the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side⑥">writable side</a> of the controlled <a data-link-type="dfn" href="#transform-stream" id="ref-for-transform-stream②">transform stream</a>, making all future interactions fail with the given <code>reason</code>. Any <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥④">chunks</a> queued for transformation will be discarded. </div>
    <emu-alg>
  1. If ! IsTransformStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. Perform ! TransformStreamDefaultControllerError(*this*, _reason_).
</emu-alg> 
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="TransformStreamDefaultController" data-dfn-type="method" data-export data-level="5.4.4.4" data-lt="terminate()" id="ts-default-controller-terminate"><span class="secno">5.4.4.4. </span><span class="content">terminate()</span></h5>
   <div class="note" role="note"> The <code>terminate</code> method will close the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side⑨">readable side</a> and error the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side⑦">writable side</a> of the
  controlled <a data-link-type="dfn" href="#transform-stream" id="ref-for-transform-stream③">transform stream</a>. This is useful when the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer⑥">transformer</a> only needs to consume a portion of the <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥⑤">chunks</a> written to the <a data-link-type="dfn" href="#writable-side" id="ref-for-writable-side⑧">writable side</a>. </div>
    <emu-alg>
  1. If ! IsTransformStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
  1. Perform ! TransformStreamDefaultControllerTerminate(*this*).
</emu-alg> 
   <h3 class="heading settled" data-level="5.5" id="ts-default-controller-abstract-ops"><span class="secno">5.5. </span><span class="content">Transform stream default controller abstract operations</span><a class="self-link" href="#ts-default-controller-abstract-ops"></a></h3>
   <h4 aoid="IsTransformStreamDefaultController" class="heading settled" data-level="5.5.1" id="is-transform-stream-default-controller" nothrow><span class="secno">5.5.1. </span><span class="content">IsTransformStreamDefaultController ( <var>x</var> )</span><a class="self-link" href="#is-transform-stream-default-controller"></a></h4>
    <emu-alg>
  1. If Type(_x_) is not Object, return *false*.
  1. If _x_ does not have an [[controlledTransformStream]] internal slot, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="SetUpTransformStreamDefaultController" class="heading settled" data-level="5.5.2" id="set-up-transform-stream-default-controller" nothrow><span class="secno">5.5.2. </span><span class="content">SetUpTransformStreamDefaultController ( <var>stream</var>, <var>controller</var>, <var>transformAlgorithm</var>, <var>flushAlgorithm</var> )</span><a class="self-link" href="#set-up-transform-stream-default-controller"></a></h4>
    <emu-alg>
  1. Assert: ! IsTransformStream(_stream_) is *true*.
  1. Assert: _stream_.[[transformStreamController]] is *undefined*.
  1. Set _controller_.[[controlledTransformStream]] to _stream_.
  1. Set _stream_.[[transformStreamController]] to _controller_.
  1. Set _controller_.[[transformAlgorithm]] to _transformAlgorithm_.
  1. Set _controller_.[[flushAlgorithm]] to _flushAlgorithm_.
</emu-alg> 
   <h4 aoid="SetUpTransformStreamDefaultControllerFromTransformer" class="heading settled" data-level="5.5.3" id="set-up-transform-stream-default-controller-from-transformer" throws><span class="secno">5.5.3. </span><span class="content">SetUpTransformStreamDefaultControllerFromTransformer ( <var>stream</var>, <var>transformer</var> )</span><a class="self-link" href="#set-up-transform-stream-default-controller-from-transformer"></a></h4>
    <emu-alg>
  1. Assert: _transformer_ is not *undefined*.
  1. Let _controller_ be ObjectCreate(the original value of `<a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class⑨">TransformStreamDefaultController</a>`'s `prototype`
     property).
  1. Let _transformAlgorithm_ be the following steps, taking a _chunk_ argument:
    1. Let _result_ be TransformStreamDefaultControllerEnqueue(_controller_, _chunk_).
    1. If _result_ is an abrupt completion, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤⑧">a promise rejected with</a> _result_.[[Value]].
    1. Otherwise, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with②②">a promise resolved with</a> *undefined*.
  1. Let _transformMethod_ be ? GetV(_transformer_, `"transform"`).
  1. If _transformMethod_ is not *undefined*,
    1. If ! IsCallable(_transformMethod_) is *false*, throw a *TypeError* exception.
    1. Set _transformAlgorithm_ to the following steps, taking a _chunk_ argument:
      1. Return ! PromiseCall(_transformMethod_, _transformer_, « _chunk_, _controller_ »).
  1. Let _flushAlgorithm_ be ? CreateAlgorithmFromUnderlyingMethod(_transformer_, `"flush"`, *0*, « controller »).
  1. Perform ! SetUpTransformStreamDefaultController(_stream_, _controller_, _transformAlgorithm_, _flushAlgorithm_).
</emu-alg> 
   <h4 aoid="TransformStreamDefaultControllerClearAlgorithms" class="heading settled" data-level="5.5.4" id="transform-stream-default-controller-clear-algorithms" nothrow><span class="secno">5.5.4. </span><span class="content">TransformStreamDefaultControllerClearAlgorithms ( <var>controller</var> )</span><a class="self-link" href="#transform-stream-default-controller-clear-algorithms"></a></h4>
   <p>This abstract operation is called once the stream is closed or errored and the algorithms will not be executed any more.
By removing the algorithm references it permits the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer⑦">transformer</a> object to be garbage collected even if the <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①②">TransformStream</a></code> itself is still referenced.</p>
   <p class="note" role="note">The results of this algorithm are not currently observable, but could become so if JavaScript eventually
adds <a href="https://github.com/tc39/proposal-weakrefs/">weak references</a>. But even without that factor,
implementations will likely want to include similar steps.</p>
    <emu-alg>
  1. Set _controller_.[[transformAlgorithm]] to *undefined*.
  1. Set _controller_.[[flushAlgorithm]] to *undefined*.
</emu-alg> 
   <h4 aoid="TransformStreamDefaultControllerEnqueue" class="heading settled" data-export data-level="5.5.5" id="transform-stream-default-controller-enqueue" throws><span class="secno">5.5.5. </span><span class="content">TransformStreamDefaultControllerEnqueue ( <var>controller</var>, <var>chunk</var> )</span><a class="self-link" href="#transform-stream-default-controller-enqueue"></a></h4>
   <p>This abstract operation can be called by other specifications that wish to enqueue <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥⑥">chunks</a> in the <a data-link-type="dfn" href="#readable-side" id="ref-for-readable-side①⓪">readable
side</a>, in the same way a developer would enqueue chunks using the stream’s associated controller object.
Specifications should <em>not</em> do this to streams they did not create.</p>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledTransformStream]].
  1. Let _readableController_ be _stream_.[[readable]].[[readableStreamController]].
  1. If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(_readableController_) is *false*, throw a *TypeError*
     exception.
  1. Let _enqueueResult_ be ReadableStreamDefaultControllerEnqueue(_readableController_, _chunk_).
  1. If _enqueueResult_ is an abrupt completion,
    1. Perform ! TransformStreamErrorWritableAndUnblockWrite(_stream_, _enqueueResult_.[[Value]]).
    1. Throw _stream_.[[readable]].[[storedError]].
  1. Let _backpressure_ be ! ReadableStreamDefaultControllerHasBackpressure(_readableController_).
  1. If _backpressure_ is not _stream_.[[backpressure]],
    1. Assert: _backpressure_ is *true*.
    1. Perform ! TransformStreamSetBackpressure(_stream_, *true*).
</emu-alg> 
   <h4 aoid="TransformStreamDefaultControllerError" class="heading settled" data-export data-level="5.5.6" id="transform-stream-default-controller-error" nothrow><span class="secno">5.5.6. </span><span class="content">TransformStreamDefaultControllerError ( <var>controller</var>, <var>e</var> )</span><a class="self-link" href="#transform-stream-default-controller-error"></a></h4>
   <p>This abstract operation can be called by other specifications that wish to move a transform stream to an errored state,
in the same way a developer would error a stream using its associated controller object. Specifications should <em>not</em> do this to streams they did not create.</p>
    <emu-alg>
  1. Perform ! TransformStreamError(_controller_.[[controlledTransformStream]], _e_).
</emu-alg> 
   <h4 aoid="TransformStreamDefaultControllerPerformTransform" class="heading settled" data-level="5.5.7" id="transform-stream-default-controller-perform-transform" nothrow><span class="secno">5.5.7. </span><span class="content">TransformStreamDefaultControllerPerformTransform ( <var>controller</var>, <var>chunk</var> )</span><a class="self-link" href="#transform-stream-default-controller-perform-transform"></a></h4>
    <emu-alg>
  1. Let _transformPromise_ be the result of performing _controller_.[[transformAlgorithm]], passing _chunk_.
  1. Return the result of <a data-link-type="dfn">reacting</a> to _transformPromise_ with the following rejection steps given the
     argument _r_:
    1. Perform ! TransformStreamError(_controller_.[[controlledTransformStream]], _r_).
    1. Throw _r_.
</emu-alg> 
   <h4 aoid="TransformStreamDefaultControllerTerminate" class="heading settled" data-export data-level="5.5.8" id="transform-stream-default-controller-terminate" nothrow><span class="secno">5.5.8. </span><span class="content">TransformStreamDefaultControllerTerminate ( <var>controller</var> )</span><a class="self-link" href="#transform-stream-default-controller-terminate"></a></h4>
   <p>This abstract operation can be called by other specifications that wish to terminate a transform stream, in the same way
a developer-created stream would be closed by its associated controller object. Specifications should <em>not</em> do
this to streams they did not create.</p>
    <emu-alg>
  1. Let _stream_ be _controller_.[[controlledTransformStream]].
  1. Let _readableController_ be _stream_.[[readable]].[[readableStreamController]].
  1. If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(_readableController_) is *true*, perform !
     ReadableStreamDefaultControllerClose(_readableController_).
  1. Let _error_ be a *TypeError* exception indicating that the stream has been terminated.
  1. Perform ! TransformStreamErrorWritableAndUnblockWrite(_stream_, _error_).
</emu-alg> 
   <h3 class="heading settled" data-level="5.6" id="ts-default-sink-abstract-ops"><span class="secno">5.6. </span><span class="content">Transform stream default sink abstract operations</span><a class="self-link" href="#ts-default-sink-abstract-ops"></a></h3>
   <h4 aoid="TransformStreamDefaultSinkWriteAlgorithm" class="heading settled" data-level="5.6.1" id="transform-stream-default-sink-write-algorithm" nothrow><span class="secno">5.6.1. </span><span class="content">TransformStreamDefaultSinkWriteAlgorithm ( <var>stream</var>, <var>chunk</var> )</span><a class="self-link" href="#transform-stream-default-sink-write-algorithm"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[writable]].[[state]] is `"writable"`.
  1. Let _controller_ be _stream_.[[transformStreamController]].
  1. If _stream_.[[backpressure]] is *true*,
    1. Let _backpressureChangePromise_ be _stream_.[[backpressureChangePromise]].
    1. Assert: _backpressureChangePromise_ is not *undefined*.
    1. Return the result of <a data-link-type="dfn">reacting</a> to _backpressureChangePromise_ with the following fulfillment steps:
      1. Let _writable_ be _stream_.[[writable]].
      1. Let _state_ be _writable_.[[state]].
      1. If _state_ is `"erroring"`, throw _writable_.[[storedError]].
      1. Assert: _state_ is `"writable"`.
      1. Return ! TransformStreamDefaultControllerPerformTransform(_controller_, _chunk_).
  1. Return ! TransformStreamDefaultControllerPerformTransform(_controller_, _chunk_).
</emu-alg> 
   <h4 aoid="TransformStreamDefaultSinkAbortAlgorithm" class="heading settled" data-level="5.6.2" id="transform-stream-default-sink-abort-algorithm" nothrow><span class="secno">5.6.2. </span><span class="content">TransformStreamDefaultSinkAbortAlgorithm ( <var>stream</var>, <var>reason</var> )</span><a class="self-link" href="#transform-stream-default-sink-abort-algorithm"></a></h4>
    <emu-alg>
  1. Perform ! TransformStreamError(_stream_, _reason_).
  1. Return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with②③">a promise resolved with</a> *undefined*.
</emu-alg> 
   <h4 aoid="TransformStreamDefaultSinkCloseAlgorithm" class="heading settled" data-level="5.6.3" id="transform-stream-default-sink-close-algorithm" nothrow><span class="secno">5.6.3. </span><span class="content">TransformStreamDefaultSinkCloseAlgorithm( <var>stream</var> )</span><a class="self-link" href="#transform-stream-default-sink-close-algorithm"></a></h4>
    <emu-alg>
  1. Let _readable_ be _stream_.[[readable]].
  1. Let _controller_ be _stream_.[[transformStreamController]].
  1. Let _flushPromise_ be the result of performing _controller_.[[flushAlgorithm]].
  1. Perform ! TransformStreamDefaultControllerClearAlgorithms(_controller_).
  1. Return the result of <a data-link-type="dfn">reacting</a> to _flushPromise_:
    1. If _flushPromise_ was fulfilled, then:
      1. If _readable_.[[state]] is `"errored"`, throw _readable_.[[storedError]].
      1. Let _readableController_ be _readable_.[[readableStreamController]].
      1. If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(_readableController_) is *true*, perform !
         ReadableStreamDefaultControllerClose(_readableController_).
    1. If _flushPromise_ was rejected with reason _r_, then:
      1. Perform ! TransformStreamError(_stream_, _r_).
      1. Throw _readable_.[[storedError]].
</emu-alg> 
   <h3 class="heading settled" data-level="5.7" id="ts-default-source-abstract-ops"><span class="secno">5.7. </span><span class="content">Transform stream default source abstract operations</span><a class="self-link" href="#ts-default-source-abstract-ops"></a></h3>
   <h4 aoid="TransformStreamDefaultSourcePullAlgorithm" class="heading settled" data-level="5.7.1" id="transform-stream-default-source-pull" nothrow><span class="secno">5.7.1. </span><span class="content">TransformStreamDefaultSourcePullAlgorithm( <var>stream</var> )</span><a class="self-link" href="#transform-stream-default-source-pull"></a></h4>
    <emu-alg>
  1. Assert: _stream_.[[backpressure]] is *true*.
  1. Assert: _stream_.[[backpressureChangePromise]] is not *undefined*.
  1. Perform ! TransformStreamSetBackpressure(_stream_, *false*).
  1. Return _stream_.[[backpressureChangePromise]].
</emu-alg> 
   <h2 class="heading settled" data-level="6" id="other-stuff"><span class="secno">6. </span><span class="content">Other stream APIs and operations</span><a class="self-link" href="#other-stuff"></a></h2>
   <h3 class="heading settled" data-level="6.1" id="qs"><span class="secno">6.1. </span><span class="content">Queuing strategies</span><a class="self-link" href="#qs"></a></h3>
   <h4 class="heading settled" data-level="6.1.1" id="qs-api"><span class="secno">6.1.1. </span><span class="content">The queuing strategy API</span><a class="self-link" href="#qs-api"></a></h4>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>The <code class="idl"><a data-link-type="idl" href="#rs-constructor" id="ref-for-rs-constructor④">ReadableStream()</a></code>, <code class="idl"><a data-link-type="idl" href="#ws-constructor" id="ref-for-ws-constructor③">WritableStream()</a></code>, and <code class="idl"><a data-link-type="idl" href="#ts-constructor" id="ref-for-ts-constructor③">TransformStream()</a></code> constructors all accept at least one argument
representing an appropriate <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy⑧">queuing strategy</a> for the stream being created. Such objects contain the following
properties:</p>
    <dl>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="queuing strategy" data-dfn-type="method" data-export id="dom-queuing-strategy-size"><code>size(<var>chunk</var>)</code></dfn> (non-byte streams only)
     <dd>
      <p>A function that computes and returns the finite non-negative size of the given <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥⑦">chunk</a> value.</p>
      <p>The result is used to determine <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①⑤">backpressure</a>, manifesting via the appropriate <code>desiredSize</code> property: either <code class="idl"><a data-link-type="idl" href="#rs-default-controller-desired-size" id="ref-for-rs-default-controller-desired-size②">defaultController.desiredSize</a></code>, <code class="idl"><a data-link-type="idl" href="#rbs-controller-desired-size" id="ref-for-rbs-controller-desired-size①">byteController.desiredSize</a></code>, or <code class="idl"><a data-link-type="idl" href="#default-writer-desired-size" id="ref-for-default-writer-desired-size⑤">writer.desiredSize</a></code>, depending on where the queuing strategy is being
    used. For readable streams, it also governs when the <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source②⑨">underlying source</a>’s <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-pull" id="ref-for-dom-underlying-source-pull⑤">pull()</a></code> method
    is called.</p>
      <p>This function has to be idempotent and not cause side effects; very strange results can occur otherwise.</p>
      <p>For <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream⑦">readable byte streams</a>, this function is not used, as chunks are always measured in bytes.</p>
     <dt><dfn class="dfn-paneled" data-dfn-for="queuing strategy" data-dfn-type="dfn" data-noexport id="queuing-strategy-highwatermark"><code>highWaterMark</code></dfn>
     <dd>
      <p>A non-negative number indicating the <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark⑥">high water mark</a> of the stream using this queuing strategy.</p>
    </dl>
    <p>Any object with these properties can be used when a queuing strategy object is expected. However, we provide two
built-in queuing strategy classes that provide a common vocabulary for certain cases: <code class="idl"><a data-link-type="idl" href="#blqs-class" id="ref-for-blqs-class">ByteLengthQueuingStrategy</a></code> and <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class④">CountQueuingStrategy</a></code>.</p>
   </div>
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="6.1.2" data-lt="ByteLengthQueuingStrategy" id="blqs-class"><span class="secno">6.1.2. </span><span class="content">Class <code>ByteLengthQueuingStrategy</code></span></h4>
   <p>A common <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy⑨">queuing strategy</a> when dealing with bytes is to wait until the accumulated <code>byteLength</code> properties of the incoming <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥⑧">chunks</a> reaches a specified high-water mark. As such, this is provided as a built-in <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy①⓪">queuing strategy</a> that can be used when constructing streams.</p>
   <div class="example" id="example-blqs">
    <a class="self-link" href="#example-blqs"></a> When creating a <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①⑥">readable stream</a> or <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①⑤">writable stream</a>, you can supply a byte-length queuing strategy
  directly: 
<pre><code class="lang-javascript highlight"><c- kr>const</c-> stream <c- o>=</c-> <c- k>new</c-> ReadableStream<c- p>(</c->
  <c- p>{</c-> <c- p>...</c-> <c- p>},</c->
  <c- k>new</c-> ByteLengthQueuingStrategy<c- p>({</c-> highWaterMark<c- o>:</c-> <c- mi>16</c-> <c- o>*</c-> <c- mi>1024</c-> <c- p>})</c->
<c- p>);</c->
</code></pre>
    <p>In this case, 16 KiB worth of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑥⑨">chunks</a> can be enqueued by the readable stream’s <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source③⓪">underlying source</a> before
  the readable stream implementation starts sending <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①⑥">backpressure</a> signals to the underlying source.</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> stream <c- o>=</c-> <c- k>new</c-> WritableStream<c- p>(</c->
  <c- p>{</c-> <c- p>...</c-> <c- p>},</c->
  <c- k>new</c-> ByteLengthQueuingStrategy<c- p>({</c-> highWaterMark<c- o>:</c-> <c- mi>32</c-> <c- o>*</c-> <c- mi>1024</c-> <c- p>})</c->
<c- p>);</c->
</code></pre>
    <p>In this case, 32 KiB worth of <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦⓪">chunks</a> can be accumulated in the writable stream’s internal queue, waiting for
  previous writes to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink②⑨">underlying sink</a> to finish, before the writable stream starts sending <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①⑦">backpressure</a> signals to any <a data-link-type="dfn" href="#producer" id="ref-for-producer⑥">producers</a>.</p>
   </div>
   <p class="note" role="note"> It is not necessary to use <code class="idl"><a data-link-type="idl" href="#blqs-class" id="ref-for-blqs-class①">ByteLengthQueuingStrategy</a></code> with <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream⑧">readable byte streams</a>, as they always measure
  chunks in bytes. Attempting to construct a byte stream with a <code class="idl"><a data-link-type="idl" href="#blqs-class" id="ref-for-blqs-class②">ByteLengthQueuingStrategy</a></code> will fail. </p>
   <h5 class="heading settled" data-level="6.1.2.1" id="blqs-class-definition"><span class="secno">6.1.2.1. </span><span class="content">Class definition</span><a class="self-link" href="#blqs-class-definition"></a></h5>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#blqs-class" id="ref-for-blqs-class③">ByteLengthQueuingStrategy</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it
would look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> ByteLengthQueuingStrategy <c- p>{</c->
  <a href="#blqs-constructor" id="ref-for-blqs-constructor">constructor</a><c- p>({</c-> highWaterMark <c- p>})</c->
  <a href="#blqs-size" id="ref-for-blqs-size">size</a><c- p>(</c->chunk<c- p>)</c->
<c- p>}</c->
</code></pre>
    <p>Each <code class="idl"><a data-link-type="idl" href="#blqs-class" id="ref-for-blqs-class④">ByteLengthQueuingStrategy</a></code> instance will additionally have an own data property <code>highWaterMark</code> set by its constructor.</p>
   </div>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="ByteLengthQueuingStrategy" data-dfn-type="constructor" data-export data-level="6.1.2.2" data-lt="ByteLengthQueuingStrategy(options)" id="blqs-constructor"><span class="secno">6.1.2.2. </span><span class="content">new
ByteLengthQueuingStrategy({ <var>highWaterMark</var> })</span></h5>
   <div class="note" role="note"> The constructor takes a non-negative number for the high-water mark, and stores it on the object as a property. </div>
    <emu-alg>
  1. Perform ! CreateDataProperty(*this*, `"highWaterMark"`, _highWaterMark_).
</emu-alg> 
   <h5 class="heading settled" data-level="6.1.2.3" id="blqs-prototype"><span class="secno">6.1.2.3. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#blqs-class" id="ref-for-blqs-class⑤">ByteLengthQueuingStrategy</a></code> prototype</span><a class="self-link" href="#blqs-prototype"></a></h5>
   <h6 class="heading settled dfn-paneled idl-code" data-dfn-for="ByteLengthQueuingStrategy" data-dfn-type="method" data-export data-level="6.1.2.3.1" data-lt="size(chunk)" id="blqs-size"><span class="secno">6.1.2.3.1. </span><span class="content">size(<var>chunk</var>)</span></h6>
   <div class="note" role="note">
     The <code>size</code> method returns the given chunk’s <code>byteLength</code> property. (If the chunk doesn’t have
  one, it will return <emu-val>undefined</emu-val>, causing the stream using this strategy to error.) 
    <p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be a <code>ByteLengthQueuingStrategy</code> object.</p>
   </div>
    <emu-alg>
  1. Return ? GetV(_chunk_, `"byteLength"`).
</emu-alg> 
   <h4 class="heading settled dfn-paneled idl-code" data-dfn-type="interface" data-export data-level="6.1.3" data-lt="CountQueuingStrategy" id="cqs-class"><span class="secno">6.1.3. </span><span class="content">Class <code>CountQueuingStrategy</code></span></h4>
   <p>A common <a data-link-type="dfn" href="#queuing-strategy" id="ref-for-queuing-strategy①①">queuing strategy</a> when dealing with streams of generic objects is to simply count the number of chunks
that have been accumulated so far, waiting until this number reaches a specified high-water mark. As such, this
strategy is also provided out of the box.</p>
   <div class="example" id="example-cqs">
    <a class="self-link" href="#example-cqs"></a> When creating a <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①⑦">readable stream</a> or <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①⑥">writable stream</a>, you can supply a count queuing strategy directly: 
<pre><code class="lang-javascript highlight"><c- kr>const</c-> stream <c- o>=</c-> <c- k>new</c-> ReadableStream<c- p>(</c->
  <c- p>{</c-> <c- p>...</c-> <c- p>},</c->
  <c- k>new</c-> CountQueuingStrategy<c- p>({</c-> highWaterMark<c- o>:</c-> <c- mi>10</c-> <c- p>})</c->
<c- p>);</c->
</code></pre>
    <p>In this case, 10 <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦①">chunks</a> (of any kind) can be enqueued by the readable stream’s <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source③①">underlying source</a> before
  the readable stream implementation starts sending <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①⑧">backpressure</a> signals to the underlying source.</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> stream <c- o>=</c-> <c- k>new</c-> WritableStream<c- p>(</c->
  <c- p>{</c-> <c- p>...</c-> <c- p>},</c->
  <c- k>new</c-> CountQueuingStrategy<c- p>({</c-> highWaterMark<c- o>:</c-> <c- mi>5</c-> <c- p>})</c->
<c- p>);</c->
</code></pre>
    <p>In this case, five <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦②">chunks</a> (of any kind) can be accumulated in the writable stream’s internal queue, waiting
  for previous writes to the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink③⓪">underlying sink</a> to finish, before the writable stream starts sending <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure①⑨">backpressure</a> signals to any <a data-link-type="dfn" href="#producer" id="ref-for-producer⑦">producers</a>.</p>
   </div>
   <h5 class="heading settled" data-level="6.1.3.1" id="cqs-class-definition"><span class="secno">6.1.3.1. </span><span class="content">Class definition</span><a class="self-link" href="#cqs-class-definition"></a></h5>
   <div class="non-normative">
    <p><em>This section is non-normative.</em></p>
    <p>If one were to write the <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class⑤">CountQueuingStrategy</a></code> class in something close to the syntax of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, it would
look like</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> CountQueuingStrategy <c- p>{</c->
  <a href="#cqs-constructor" id="ref-for-cqs-constructor">constructor</a><c- p>({</c-> highWaterMark <c- p>})</c->
  <a href="#cqs-size" id="ref-for-cqs-size">size</a><c- p>(</c->chunk<c- p>)</c->
<c- p>}</c->
</code></pre>
    <p>Each <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class⑥">CountQueuingStrategy</a></code> instance will additionally have an own data property <code>highWaterMark</code> set by its constructor.</p>
   </div>
   <h5 class="heading settled dfn-paneled idl-code" data-dfn-for="CountQueuingStrategy" data-dfn-type="constructor" data-export data-level="6.1.3.2" data-lt="CountQueuingStrategy(options)" id="cqs-constructor"><span class="secno">6.1.3.2. </span><span class="content">new
CountQueuingStrategy({ <var>highWaterMark</var> })</span></h5>
   <div class="note" role="note"> The constructor takes a non-negative number for the high-water mark, and stores it on the object as a property. </div>
    <emu-alg>
  1. Perform ! CreateDataProperty(*this*, `"highWaterMark"`, _highWaterMark_).
</emu-alg> 
   <h5 class="heading settled" data-level="6.1.3.3" id="cqs-prototype"><span class="secno">6.1.3.3. </span><span class="content">Properties of the <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class⑦">CountQueuingStrategy</a></code> prototype</span><a class="self-link" href="#cqs-prototype"></a></h5>
   <h6 class="heading settled dfn-paneled idl-code" data-dfn-for="CountQueuingStrategy" data-dfn-type="method" data-export data-level="6.1.3.3.1" data-lt="size()" id="cqs-size"><span class="secno">6.1.3.3.1. </span><span class="content">size()</span></h6>
   <div class="note" role="note">
     The <code>size</code> method returns one always, so that the total queue size is a count of the number of chunks in
  the queue. 
    <p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be a <code>CountQueuingStrategy</code> object.</p>
   </div>
    <emu-alg>
  1. Return *1*.
</emu-alg> 
   <h3 class="heading settled" data-level="6.2" id="queue-with-sizes"><span class="secno">6.2. </span><span class="content">Queue-with-sizes operations</span><a class="self-link" href="#queue-with-sizes"></a></h3>
   <p>The streams in this specification use a "queue-with-sizes" data structure to store queued up values, along with their
determined sizes. Various specification objects contain a queue-with-sizes, represented by the object having two paired
internal slots, always named [[queue]] and [[queueTotalSize]]. [[queue]] is a List of Records with [[value]] and
[[size]] fields, and [[queueTotalSize]] is a JavaScript <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type" id="ref-for-sec-ecmascript-language-types-number-type">Number</a></code>, i.e. a double-precision floating point number.</p>
   <p>The following abstract operations are used when operating on objects that contain queues-with-sizes, in order to ensure
that the two internal slots stay synchronized.</p>
   <p class="warning">Due to the limited precision of floating-point arithmetic, the framework specified here, of keeping a
running total in the [[queueTotalSize]] slot, is <em>not</em> equivalent to adding up the size of all <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦③">chunks</a> in
[[queue]]. (However, this only makes a difference when there is a huge (~10<sup>15</sup>) variance in size between
chunks, or when trillions of chunks are enqueued.)</p>
   <h4 aoid="DequeueValue" class="heading settled" data-level="6.2.1" id="dequeue-value" nothrow><span class="secno">6.2.1. </span><span class="content">DequeueValue ( <var>container</var> )</span><a class="self-link" href="#dequeue-value"></a></h4>
    <emu-alg>
  1. Assert: _container_ has [[queue]] and [[queueTotalSize]] internal slots.
  1. Assert: _container_.[[queue]] is not empty.
  1. Let _pair_ be the first element of _container_.[[queue]].
  1. Remove _pair_ from _container_.[[queue]], shifting all other elements downward (so that the second becomes the
     first, and so on).
  1. Set _container_.[[queueTotalSize]] to _container_.[[queueTotalSize]] − _pair_.[[size]].
  1. If _container_.[[queueTotalSize]] &lt; *0*, set _container_.[[queueTotalSize]] to *0*. (This can occur due to
     rounding errors.)
  1. Return _pair_.[[value]].
</emu-alg> 
   <h4 aoid="EnqueueValueWithSize" class="heading settled" data-level="6.2.2" id="enqueue-value-with-size" throws><span class="secno">6.2.2. </span><span class="content">EnqueueValueWithSize ( <var>container</var>, <var>value</var>, <var>size</var> )</span><a class="self-link" href="#enqueue-value-with-size"></a></h4>
    <emu-alg>
  1. Assert: _container_ has [[queue]] and [[queueTotalSize]] internal slots.
  1. Let _size_ be ? ToNumber(_size_).
  1. If ! IsFiniteNonNegativeNumber(_size_) is *false*, throw a *RangeError* exception.
  1. Append Record {[[value]]: _value_, [[size]]: _size_} as the last element of _container_.[[queue]].
  1. Set _container_.[[queueTotalSize]] to _container_.[[queueTotalSize]] + _size_.
</emu-alg> 
   <h4 aoid="PeekQueueValue" class="heading settled" data-level="6.2.3" id="peek-queue-value" nothrow><span class="secno">6.2.3. </span><span class="content">PeekQueueValue ( <var>container</var> )</span><a class="self-link" href="#peek-queue-value"></a></h4>
    <emu-alg>
  1. Assert: _container_ has [[queue]] and [[queueTotalSize]] internal slots.
  1. Assert: _container_.[[queue]] is not empty.
  1. Let _pair_ be the first element of _container_.[[queue]].
  1. Return _pair_.[[value]].
</emu-alg> 
   <h4 aoid="ResetQueue" class="heading settled" data-level="6.2.4" id="reset-queue" nothrow><span class="secno">6.2.4. </span><span class="content">ResetQueue ( <var>container</var> )</span><a class="self-link" href="#reset-queue"></a></h4>
    <emu-alg>
  1. Assert: _container_ has [[queue]] and [[queueTotalSize]] internal slots.
  1. Set _container_.[[queue]] to a new empty List.
  1. Set _container_.[[queueTotalSize]] to *0*.
</emu-alg> 
   <h3 class="heading settled" data-level="6.3" id="misc-abstract-ops"><span class="secno">6.3. </span><span class="content">Miscellaneous operations</span><a class="self-link" href="#misc-abstract-ops"></a></h3>
   <p>A few abstract operations are used in this specification for utility purposes. We define them here.</p>
   <h4 aoid="CreateAlgorithmFromUnderlyingMethod" class="heading settled" data-level="6.3.1" id="create-algorithm-from-underlying-method" throws><span class="secno">6.3.1. </span><span class="content">CreateAlgorithmFromUnderlyingMethod ( <var>underlyingObject</var>, <var>methodName</var>, <var>algoArgCount</var>, <var>extraArgs</var> )</span><a class="self-link" href="#create-algorithm-from-underlying-method"></a></h4>
    <emu-alg>
  1. Assert: _underlyingObject_ is not *undefined*.
  1. Assert: ! IsPropertyKey(_methodName_) is *true*.
  1. Assert: _algoArgCount_ is *0* or *1*.
  1. Assert: _extraArgs_ is a List.
  1. Let _method_ be ? GetV(_underlyingObject_, _methodName_).
  1. If _method_ is not *undefined*,
    1. If ! IsCallable(_method_) is *false*, throw a *TypeError* exception.
    1. If _algoArgCount_ is *0*, return an algorithm that performs the following steps:
      1. Return ! PromiseCall(_method_, _underlyingObject_, _extraArgs_).
    1. Otherwise, return an algorithm that performs the following steps, taking an _arg_ argument:
      1. Let _fullArgs_ be a List consisting of _arg_ followed by the elements of _extraArgs_ in order.
      1. Return ! PromiseCall(_method_, _underlyingObject_, _fullArgs_).
  1. Return an algorithm which returns <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with②④">a promise resolved with</a> *undefined*.
</emu-alg> 
   <h4 aoid="InvokeOrNoop" class="heading settled" data-level="6.3.2" id="invoke-or-noop" throws><span class="secno">6.3.2. </span><span class="content">InvokeOrNoop ( <var>O</var>, <var>P</var>, <var>args</var> )</span><a class="self-link" href="#invoke-or-noop"></a></h4>
   <div class="note" role="note"> InvokeOrNoop is a slight modification of the <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a> <a data-link-type="abstract-op" href="https://tc39.github.io/ecma262/#sec-invoke" id="ref-for-sec-invoke">Invoke</a> abstract operation to return <emu-val>undefined</emu-val> when the method is not present. </div>
    <emu-alg>
  1. Assert: _O_ is not *undefined*.
  1. Assert: ! IsPropertyKey(_P_) is *true*.
  1. Assert: _args_ is a List.
  1. Let _method_ be ? GetV(_O_, _P_).
  1. If _method_ is *undefined*, return *undefined*.
  1. Return ? Call(_method_, _O_, _args_).
</emu-alg> 
   <h4 aoid="IsFiniteNonNegativeNumber" class="heading settled" data-level="6.3.3" id="is-finite-non-negative-number" nothrow><span class="secno">6.3.3. </span><span class="content">IsFiniteNonNegativeNumber ( <var>v</var> )</span><a class="self-link" href="#is-finite-non-negative-number"></a></h4>
    <emu-alg>
  1. If ! IsNonNegativeNumber(_v_) is *false*, return *false*.
  1. If _v_ is *+∞*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="IsNonNegativeNumber" class="heading settled" data-level="6.3.4" id="is-non-negative-number" nothrow><span class="secno">6.3.4. </span><span class="content">IsNonNegativeNumber ( <var>v</var> )</span><a class="self-link" href="#is-non-negative-number"></a></h4>
    <emu-alg>
  1. If Type(_v_) is not Number, return *false*.
  1. If _v_ is *NaN*, return *false*.
  1. If _v_ &lt; *0*, return *false*.
  1. Return *true*.
</emu-alg> 
   <h4 aoid="PromiseCall" class="heading settled" data-level="6.3.5" id="promise-call" nothrow><span class="secno">6.3.5. </span><span class="content">PromiseCall ( <var>F</var>, <var>V</var>, <var>args</var> )</span><a class="self-link" href="#promise-call"></a></h4>
   <div class="note" role="note"> This encapsulates the relevant promise-related parts of the Web IDL <a data-link-type="dfn" href="https://heycam.github.io/webidl/#call-a-user-objects-operation" id="ref-for-call-a-user-objects-operation">call a user object’s operation</a> algorithm
  for use while we work on <a href="https://github.com/whatwg/streams/issues/963">moving to Web IDL</a>. </div>
    <emu-alg>
  1. Assert: ! IsCallable(_F_) is *true*.
  1. Assert: _V_ is not *undefined*.
  1. Assert: _args_ is a List.
  1. Let _returnValue_ be Call(_F_, _V_, _args_).
  1. If _returnValue_ is an abrupt completion, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with" id="ref-for-a-promise-rejected-with⑤⑨">a promise rejected with</a> _returnValue_.[[Value]].
  1. Otherwise, return <a data-link-type="dfn" href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with" id="ref-for-a-promise-resolved-with②⑤">a promise resolved with</a> _returnValue_.[[Value]].
</emu-alg> 
   <h4 aoid="TransferArrayBuffer" class="heading settled" data-level="6.3.6" id="transfer-array-buffer" nothrow><span class="secno">6.3.6. </span><span class="content">TransferArrayBuffer ( <var>O</var> )</span><a class="self-link" href="#transfer-array-buffer"></a></h4>
    <emu-alg>
  1. Assert: Type(_O_) is Object.
  1. Assert: _O_ has an [[ArrayBufferData]] internal slot.
  1. Assert: ! IsDetachedBuffer(_O_) is *false*.
  1. Let _arrayBufferData_ be _O_.[[ArrayBufferData]].
  1. Let _arrayBufferByteLength_ be _O_.[[ArrayBufferByteLength]].
  1. Perform ! DetachArrayBuffer(_O_).
  1. Return a new <a class="idl-code" data-link-type="interface" href="https://tc39.github.io/ecma262/#sec-arraybuffer-objects" id="ref-for-sec-arraybuffer-objects③"><code>ArrayBuffer</code></a> object (created in the current Realm Record) whose
     [[ArrayBufferData]] internal slot value is _arrayBufferData_ and whose [[ArrayBufferByteLength]] internal slot
     value is _arrayBufferByteLength_.
</emu-alg> 
   <h4 aoid="ValidateAndNormalizeHighWaterMark" class="heading settled" data-level="6.3.7" id="validate-and-normalize-high-water-mark" throws><span class="secno">6.3.7. </span><span class="content">ValidateAndNormalizeHighWaterMark ( <var>highWaterMark</var> )</span><a class="self-link" href="#validate-and-normalize-high-water-mark"></a></h4>
    <emu-alg>
  1. Set _highWaterMark_ to ? ToNumber(_highWaterMark_).
  1. If _highWaterMark_ is *NaN* or _highWaterMark_ &lt; *0*, throw a *RangeError* exception.
     <p class="note" role="note">*+∞* is explicitly allowed as a valid <a data-link-type="dfn" href="#high-water-mark" id="ref-for-high-water-mark⑦">high water mark</a>. It causes <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure②⓪">backpressure</a> to never be applied.</p>
  1. Return _highWaterMark_.
</emu-alg> 
   <h4 aoid="MakeSizeAlgorithmFromSizeFunction" class="heading settled" data-level="6.3.8" id="make-size-algorithm-from-size-function" throws><span class="secno">6.3.8. </span><span class="content">MakeSizeAlgorithmFromSizeFunction ( <var>size</var> )</span><a class="self-link" href="#make-size-algorithm-from-size-function"></a></h4>
    <emu-alg>
  1. If _size_ is *undefined*, return an algorithm that returns *1*.
  1. If ! IsCallable(_size_) is *false*, throw a *TypeError* exception.
  1. Return an algorithm that performs the following steps, taking a _chunk_ argument:
    1. Return ? Call(_size_, *undefined*, « _chunk_ »).
</emu-alg> 
   <h2 class="heading settled" data-level="7" id="globals"><span class="secno">7. </span><span class="content">Global properties</span><a class="self-link" href="#globals"></a></h2>
   <p>The following constructors must be exposed on the global object as data properties of the same name:</p>
   <ul class="brief">
    <li> <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③⑥">ReadableStream</a></code> 
    <li> <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class①⑨">WritableStream</a></code> 
    <li> <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①③">TransformStream</a></code> 
    <li> <code class="idl"><a data-link-type="idl" href="#blqs-class" id="ref-for-blqs-class⑥">ByteLengthQueuingStrategy</a></code> 
    <li> <code class="idl"><a data-link-type="idl" href="#cqs-class" id="ref-for-cqs-class⑧">CountQueuingStrategy</a></code> 
   </ul>
   <p>The attributes of these properties must be { [[Writable]]: <emu-val>true</emu-val>, [[Enumerable]]: <emu-val>false</emu-val>,
[[Configurable]]: <emu-val>true</emu-val> }.</p>
   <div class="note" role="note"> The <code class="idl"><a data-link-type="idl" href="#default-reader-class" id="ref-for-default-reader-class⑨">ReadableStreamDefaultReader</a></code>, <code class="idl"><a data-link-type="idl" href="#byob-reader-class" id="ref-for-byob-reader-class⑧">ReadableStreamBYOBReader</a></code>, <code class="idl"><a data-link-type="idl" href="#rs-default-controller-class" id="ref-for-rs-default-controller-class①②">ReadableStreamDefaultController</a></code>, <code class="idl"><a data-link-type="idl" href="#rbs-controller-class" id="ref-for-rbs-controller-class①⑤">ReadableByteStreamController</a></code>, <code class="idl"><a data-link-type="idl" href="#default-writer-class" id="ref-for-default-writer-class⑨">WritableStreamDefaultWriter</a></code>, <code class="idl"><a data-link-type="idl" href="#ws-default-controller-class" id="ref-for-ws-default-controller-class①②">WritableStreamDefaultController</a></code>, and <code class="idl"><a data-link-type="idl" href="#ts-default-controller-class" id="ref-for-ts-default-controller-class①⓪">TransformStreamDefaultController</a></code> classes are specifically not exposed, as they are not independently useful. </div>
   <h2 class="heading settled" data-level="8" id="creating-examples"><span class="secno">8. </span><span class="content">Examples of creating streams</span><a class="self-link" href="#creating-examples"></a></h2>
   <div class="non-normative">
    <p><em>This section, and all its subsections, are non-normative.</em></p>
    <p>The previous examples throughout the standard have focused on how to use streams. Here we show how to create a stream,
using the <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③⑦">ReadableStream</a></code> or <code class="idl"><a data-link-type="idl" href="#ws-class" id="ref-for-ws-class②⓪">WritableStream</a></code> constructors.</p>
    <h3 class="heading settled" data-level="8.1" id="example-rs-push-no-backpressure"><span class="secno">8.1. </span><span class="content">A readable stream with an underlying push source (no backpressure support)</span><a class="self-link" href="#example-rs-push-no-backpressure"></a></h3>
    <p>The following function creates <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①⑧">readable streams</a> that wrap <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/web-sockets.html#websocket" id="ref-for-websocket">WebSocket</a></code> instances <a data-link-type="biblio" href="#biblio-html">[HTML]</a>, which are <a data-link-type="dfn" href="#push-source" id="ref-for-push-source②">push sources</a> that do not support backpressure signals. It illustrates how, when adapting a push source, usually most of the work
happens in the <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-start" id="ref-for-dom-underlying-source-start③">start()</a></code> function.</p>
<pre><code class="lang-javascript highlight"><c- a>function</c-> makeReadableWebSocketStream<c- p>(</c->url<c- p>,</c-> protocols<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> ws <c- o>=</c-> <c- k>new</c-> WebSocket<c- p>(</c->url<c- p>,</c-> protocols<c- p>);</c->
  ws<c- p>.</c->binaryType <c- o>=</c-> <c- u>"arraybuffer"</c-><c- p>;</c->

  <c- k>return</c-> <c- k>new</c-> ReadableStream<c- p>({</c->
    start<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
      ws<c- p>.</c->onmessage <c- o>=</c-> event <c- p>=></c-> controller<c- p>.</c->enqueue<c- p>(</c->event<c- p>.</c->data<c- p>);</c->
      ws<c- p>.</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> controller<c- p>.</c->close<c- p>();</c->
      ws<c- p>.</c->onerror <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> controller<c- p>.</c->error<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The WebSocket errored!"</c-><c- p>));</c->
    <c- p>},</c->

    cancel<c- p>()</c-> <c- p>{</c->
      ws<c- p>.</c->close<c- p>();</c->
    <c- p>}</c->
  <c- p>});</c->
<c- p>}</c->
</code></pre>
    <p>We can then use this function to create readable streams for a web socket, and pipe that stream to an arbitrary
writable stream:</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> webSocketStream <c- o>=</c-> makeReadableWebSocketStream<c- p>(</c-><c- u>"wss://example.com:443/"</c-><c- p>,</c-> <c- u>"protocol"</c-><c- p>);</c->

webSocketStream<c- p>.</c->pipeTo<c- p>(</c->writableStream<c- p>)</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"All data successfully written!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Something went wrong!"</c-><c- p>,</c-> e<c- p>));</c->
</code></pre>
    <div class="note" id="note-web-socket-wrapping-examples" role="note">
     <a class="self-link" href="#note-web-socket-wrapping-examples"></a> This specific style of wrapping a web socket interprets web socket messages directly as <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦④">chunks</a>.
  This can be a convenient abstraction, for example when <a data-link-type="dfn" href="#piping" id="ref-for-piping①③">piping</a> to a <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①⑦">writable stream</a> or <a data-link-type="dfn" href="#transform-stream" id="ref-for-transform-stream④">transform
  stream</a> for which each web socket message makes sense as a chunk to consume or transform. 
     <p>However, often when people talk about "adding streams support to web sockets", they are hoping instead for a new
  capability to send an individual web socket message in a streaming fashion, so that e.g. a file could be transferred
  in a single message without holding all of its contents in memory on the client side. To accomplish this goal, we’d
  instead want to allow individual web socket messages to themselves be <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③⑧">ReadableStream</a></code> instances. That isn’t what we
  show in the above example.</p>
     <p>For more background, see <a href="https://github.com/w3c/webrtc-pc/issues/1732#issuecomment-358428651">this
  discussion</a>.</p>
    </div>
    <h3 class="heading settled" data-level="8.2" id="example-rs-push-backpressure"><span class="secno">8.2. </span><span class="content">A readable stream with an underlying push source and backpressure support</span><a class="self-link" href="#example-rs-push-backpressure"></a></h3>
    <p>The following function returns <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream①⑨">readable streams</a> that wrap "backpressure sockets," which are hypothetical objects
that have the same API as web sockets, but also provide the ability to pause and resume the flow of data with their <code>readStop</code> and <code>readStart</code> methods. In doing so, this example shows how to apply <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure②①">backpressure</a> to <a data-link-type="dfn" href="#underlying-source" id="ref-for-underlying-source③②">underlying sources</a> that support it.</p>
<pre><code class="lang-javascript highlight"><c- a>function</c-> makeReadableBackpressureSocketStream<c- p>(</c->host<c- p>,</c-> port<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> socket <c- o>=</c-> createBackpressureSocket<c- p>(</c->host<c- p>,</c-> port<c- p>);</c->

  <c- k>return</c-> <c- k>new</c-> ReadableStream<c- p>({</c->
    start<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
      socket<c- p>.</c->ondata <c- o>=</c-> event <c- p>=></c-> <c- p>{</c->
        controller<c- p>.</c->enqueue<c- p>(</c->event<c- p>.</c->data<c- p>);</c->

        <c- k>if</c-> <c- p>(</c->controller<c- p>.</c->desiredSize <c- o>&lt;=</c-> <c- mi>0</c-><c- p>)</c-> <c- p>{</c->
          <c- c1>// The internal queue is full, so propagate</c->
          <c- c1>// the backpressure signal to the underlying source.</c->
          socket<c- p>.</c->readStop<c- p>();</c->
        <c- p>}</c->
      <c- p>};</c->

      socket<c- p>.</c->onend <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> controller<c- p>.</c->close<c- p>();</c->
      socket<c- p>.</c->onerror <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> controller<c- p>.</c->error<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The socket errored!"</c-><c- p>));</c->
    <c- p>},</c->

    pull<c- p>()</c-> <c- p>{</c->
      <c- c1>// This is called if the internal queue has been emptied, but the</c->
      <c- c1>// stream’s consumer still wants more data. In that case, restart</c->
      <c- c1>// the flow of data if we have previously paused it.</c->
      socket<c- p>.</c->readStart<c- p>();</c->
    <c- p>},</c->

    cancel<c- p>()</c-> <c- p>{</c->
      socket<c- p>.</c->close<c- p>();</c->
    <c- p>}</c->
  <c- p>});</c->
<c- p>}</c->
</code></pre>
    <p>We can then use this function to create readable streams for such "backpressure sockets" in the same way we do for web
sockets. This time, however, when we pipe to a destination that cannot accept data as fast as the socket is producing
it, or if we leave the stream alone without reading from it for some time, a backpressure signal will be sent to the
socket.</p>
    <h3 class="heading settled" data-level="8.3" id="example-rbs-push"><span class="secno">8.3. </span><span class="content">A readable byte stream with an underlying push source (no backpressure support)</span><a class="self-link" href="#example-rbs-push"></a></h3>
    <p>The following function returns <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream⑨">readable byte streams</a> that wraps a hypothetical UDP socket API, including a
promise-returning <code>select2()</code> method that is meant to be evocative of the POSIX select(2) system call.</p>
    <p>Since the UDP protocol does not have any built-in backpressure support, the backpressure signal given by <code class="idl"><a data-link-type="idl" href="#rbs-controller-desired-size" id="ref-for-rbs-controller-desired-size②">desiredSize</a></code> is ignored, and the stream ensures that when data is available from the
socket but not yet requested by the developer, it is enqueued in the stream’s <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues⑧">internal queue</a>, to avoid overflow
of the kernel-space queue and a consequent loss of data.</p>
    <p>This has some interesting consequences for how <a data-link-type="dfn" href="#consumer" id="ref-for-consumer⑦">consumers</a> interact with the stream. If the consumer does not read
data as fast as the socket produces it, the <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦⑤">chunks</a> will remain in the stream’s <a data-link-type="dfn" href="#internal-queues" id="ref-for-internal-queues⑨">internal queue</a> indefinitely. In this case, using a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers⑧">BYOB reader</a> will cause an extra copy, to move the data from the stream’s
internal queue to the developer-supplied buffer. However, if the consumer consumes the data quickly enough, a <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers⑨">BYOB
reader</a> will allow zero-copy reading directly into developer-supplied buffers.</p>
    <p>(You can imagine a more complex version of this example which uses <code class="idl"><a data-link-type="idl" href="#rbs-controller-desired-size" id="ref-for-rbs-controller-desired-size③">desiredSize</a></code> to
inform an out-of-band backpressure signaling mechanism, for example by sending a message down the socket to adjust the
rate of data being sent. That is left as an exercise for the reader.)</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> DEFAULT_CHUNK_SIZE <c- o>=</c-> <c- mi>65536</c-><c- p>;</c->

<c- a>function</c-> makeUDPSocketStream<c- p>(</c->host<c- p>,</c-> port<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> socket <c- o>=</c-> createUDPSocket<c- p>(</c->host<c- p>,</c-> port<c- p>);</c->

  <c- k>return</c-> <c- k>new</c-> ReadableStream<c- p>({</c->
    type<c- o>:</c-> <c- u>"bytes"</c-><c- p>,</c->

    start<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
      readRepeatedly<c- p>().</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> controller<c- p>.</c->error<c- p>(</c->e<c- p>));</c->

      <c- a>function</c-> readRepeatedly<c- p>()</c-> <c- p>{</c->
        <c- k>return</c-> socket<c- p>.</c->select2<c- p>().</c->then<c- p>(()</c-> <c- p>=></c-> <c- p>{</c->
          <c- c1>// Since the socket can become readable even when there’s</c->
          <c- c1>// no pending BYOB requests, we need to handle both cases.</c->
          <c- a>let</c-> bytesRead<c- p>;</c->
          <c- k>if</c-> <c- p>(</c->controller<c- p>.</c->byobRequest<c- p>)</c-> <c- p>{</c->
            <c- kr>const</c-> v <c- o>=</c-> controller<c- p>.</c->byobRequest<c- p>.</c->view<c- p>;</c->
            bytesRead <c- o>=</c-> socket<c- p>.</c->readInto<c- p>(</c->v<c- p>.</c->buffer<c- p>,</c-> v<c- p>.</c->byteOffset<c- p>,</c-> v<c- p>.</c->byteLength<c- p>);</c->
            controller<c- p>.</c->byobRequest<c- p>.</c->respond<c- p>(</c->bytesRead<c- p>);</c->
          <c- p>}</c-> <c- k>else</c-> <c- p>{</c->
            <c- kr>const</c-> buffer <c- o>=</c-> <c- k>new</c-> ArrayBuffer<c- p>(</c->DEFAULT_CHUNK_SIZE<c- p>);</c->
            bytesRead <c- o>=</c-> socket<c- p>.</c->readInto<c- p>(</c->buffer<c- p>,</c-> <c- mi>0</c-><c- p>,</c-> DEFAULT_CHUNK_SIZE<c- p>);</c->
            controller<c- p>.</c->enqueue<c- p>(</c-><c- k>new</c-> Uint8Array<c- p>(</c->buffer<c- p>,</c-> <c- mi>0</c-><c- p>,</c-> bytesRead<c- p>));</c->
          <c- p>}</c->

          <c- k>if</c-> <c- p>(</c->bytesRead <c- o>===</c-> <c- mi>0</c-><c- p>)</c-> <c- p>{</c->
            controller<c- p>.</c->close<c- p>();</c->
            <c- k>return</c-><c- p>;</c->
          <c- p>}</c->

          <c- k>return</c-> readRepeatedly<c- p>();</c->
        <c- p>});</c->
      <c- p>}</c->
    <c- p>},</c->

    cancel<c- p>()</c-> <c- p>{</c->
      socket<c- p>.</c->close<c- p>();</c->
    <c- p>}</c->
  <c- p>});</c->
<c- p>}</c->
</code></pre>
    <p><code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class③⑨">ReadableStream</a></code> instances returned from this function can now vend <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers①⓪">BYOB readers</a>, with all of the
aforementioned benefits and caveats.</p>
    <h3 class="heading settled" data-level="8.4" id="example-rs-pull"><span class="secno">8.4. </span><span class="content">A readable stream with an underlying pull source</span><a class="self-link" href="#example-rs-pull"></a></h3>
    <p>The following function returns <a data-link-type="dfn" href="#readable-stream" id="ref-for-readable-stream②⓪">readable streams</a> that wrap portions of the <a href="https://nodejs.org/api/fs.html">Node.js file system API</a> (which themselves map fairly directly to C’s <code>fopen</code>, <code>fread</code>, and <code>fclose</code> trio). Files are a typical example of <a data-link-type="dfn" href="#pull-source" id="ref-for-pull-source②">pull
sources</a>. Note how in contrast to the examples with push sources, most of the work here happens on-demand in the <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-pull" id="ref-for-dom-underlying-source-pull⑥">pull()</a></code> function, and not at startup time in the <code class="idl"><a data-link-type="idl" href="#dom-underlying-source-start" id="ref-for-dom-underlying-source-start④">start()</a></code> function.</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> fs <c- o>=</c-> require<c- p>(</c-><c- u>"pr/fs"</c-><c- p>);</c-> <c- c1>// https://github.com/jden/pr</c->
<c- kr>const</c-> CHUNK_SIZE <c- o>=</c-> <c- mi>1024</c-><c- p>;</c->

<c- a>function</c-> makeReadableFileStream<c- p>(</c->filename<c- p>)</c-> <c- p>{</c->
  <c- a>let</c-> fd<c- p>;</c->
  <c- a>let</c-> position <c- o>=</c-> <c- mi>0</c-><c- p>;</c->

  <c- k>return</c-> <c- k>new</c-> ReadableStream<c- p>({</c->
    start<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->open<c- p>(</c->filename<c- p>,</c-> <c- u>"r"</c-><c- p>).</c->then<c- p>(</c->result <c- p>=></c-> <c- p>{</c->
        fd <c- o>=</c-> result<c- p>;</c->
      <c- p>});</c->
    <c- p>},</c->

    pull<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
      <c- kr>const</c-> buffer <c- o>=</c-> <c- k>new</c-> ArrayBuffer<c- p>(</c->CHUNK_SIZE<c- p>);</c->

      <c- k>return</c-> fs<c- p>.</c->read<c- p>(</c->fd<c- p>,</c-> buffer<c- p>,</c-> <c- mi>0</c-><c- p>,</c-> CHUNK_SIZE<c- p>,</c-> position<c- p>).</c->then<c- p>(</c->bytesRead <c- p>=></c-> <c- p>{</c->
        <c- k>if</c-> <c- p>(</c->bytesRead <c- o>===</c-> <c- mi>0</c-><c- p>)</c-> <c- p>{</c->
          <c- k>return</c-> fs<c- p>.</c->close<c- p>(</c->fd<c- p>).</c->then<c- p>(()</c-> <c- p>=></c-> controller<c- p>.</c->close<c- p>());</c->
        <c- p>}</c-> <c- k>else</c-> <c- p>{</c->
          position <c- o>+=</c-> bytesRead<c- p>;</c->
          controller<c- p>.</c->enqueue<c- p>(</c-><c- k>new</c-> Uint8Array<c- p>(</c->buffer<c- p>,</c-> <c- mi>0</c-><c- p>,</c-> bytesRead<c- p>));</c->
        <c- p>}</c->
      <c- p>});</c->
    <c- p>},</c->

    cancel<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->close<c- p>(</c->fd<c- p>);</c->
    <c- p>}</c->
  <c- p>});</c->
<c- p>}</c->
</code></pre>
    <p>We can then create and use readable streams for files just as we could before for sockets.</p>
    <h3 class="heading settled" data-level="8.5" id="example-rbs-pull"><span class="secno">8.5. </span><span class="content">A readable byte stream with an underlying pull source</span><a class="self-link" href="#example-rbs-pull"></a></h3>
    <p>The following function returns <a data-link-type="dfn" href="#readable-byte-stream" id="ref-for-readable-byte-stream①⓪">readable byte streams</a> that allow efficient zero-copy reading of files, again
using the <a href="https://nodejs.org/api/fs.html">Node.js file system API</a>. Instead of using a predetermined chunk
size of 1024, it attempts to fill the developer-supplied buffer, allowing full control.</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> fs <c- o>=</c-> require<c- p>(</c-><c- u>"pr/fs"</c-><c- p>);</c-> <c- c1>// https://github.com/jden/pr</c->
<c- kr>const</c-> DEFAULT_CHUNK_SIZE <c- o>=</c-> <c- mi>1024</c-><c- p>;</c->

<c- a>function</c-> makeReadableByteFileStream<c- p>(</c->filename<c- p>)</c-> <c- p>{</c->
  <c- a>let</c-> fd<c- p>;</c->
  <c- a>let</c-> position <c- o>=</c-> <c- mi>0</c-><c- p>;</c->

  <c- k>return</c-> <c- k>new</c-> ReadableStream<c- p>({</c->
    type<c- o>:</c-> <c- u>"bytes"</c-><c- p>,</c->

    start<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->open<c- p>(</c->filename<c- p>,</c-> <c- u>"r"</c-><c- p>).</c->then<c- p>(</c->result <c- p>=></c-> <c- p>{</c->
        fd <c- o>=</c-> result<c- p>;</c->
      <c- p>});</c->
    <c- p>},</c->

    pull<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
      <c- c1>// Even when the consumer is using the default reader, the auto-allocation</c->
      <c- c1>// feature allocates a buffer and passes it to us via byobRequest.</c->
      <c- kr>const</c-> v <c- o>=</c-> controller<c- p>.</c->byobRequest<c- p>.</c->view<c- p>;</c->

      <c- k>return</c-> fs<c- p>.</c->read<c- p>(</c->fd<c- p>,</c-> v<c- p>.</c->buffer<c- p>,</c-> v<c- p>.</c->byteOffset<c- p>,</c-> v<c- p>.</c->byteLength<c- p>,</c-> position<c- p>).</c->then<c- p>(</c->bytesRead <c- p>=></c-> <c- p>{</c->
        <c- k>if</c-> <c- p>(</c->bytesRead <c- o>===</c-> <c- mi>0</c-><c- p>)</c-> <c- p>{</c->
          <c- k>return</c-> fs<c- p>.</c->close<c- p>(</c->fd<c- p>).</c->then<c- p>(()</c-> <c- p>=></c-> controller<c- p>.</c->close<c- p>());</c->
        <c- p>}</c-> <c- k>else</c-> <c- p>{</c->
          position <c- o>+=</c-> bytesRead<c- p>;</c->
          controller<c- p>.</c->byobRequest<c- p>.</c->respond<c- p>(</c->bytesRead<c- p>);</c->
        <c- p>}</c->
      <c- p>});</c->
    <c- p>},</c->

    cancel<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->close<c- p>(</c->fd<c- p>);</c->
    <c- p>},</c->

    autoAllocateChunkSize<c- o>:</c-> DEFAULT_CHUNK_SIZE
  <c- p>});</c->
<c- p>}</c->
</code></pre>
    <p>With this in hand, we can create and use <a data-link-type="dfn" href="#byob-readers" id="ref-for-byob-readers①①">BYOB readers</a> for the returned <code class="idl"><a data-link-type="idl" href="#rs-class" id="ref-for-rs-class④⓪">ReadableStream</a></code>. But we can
also create <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers⑥">default readers</a>, using them in the same simple and generic manner as usual. The adaptation between
the low-level byte tracking of the <a data-link-type="dfn" href="#underlying-byte-source" id="ref-for-underlying-byte-source⑦">underlying byte source</a> shown here, and the higher-level chunk-based
consumption of a <a data-link-type="dfn" href="#default-readers" id="ref-for-default-readers⑦">default reader</a>, is all taken care of automatically by the streams implementation. The
auto-allocation feature, via the <code><a data-link-type="dfn" href="#underlying-source-autoallocatechunksize" id="ref-for-underlying-source-autoallocatechunksize">autoAllocateChunkSize</a></code> option, even allows
us to write less code, compared to the manual branching in <a href="#example-rbs-push">§ 8.3 A readable byte stream with an underlying push source (no backpressure support)</a>.</p>
    <h3 class="heading settled" data-level="8.6" id="example-ws-no-backpressure"><span class="secno">8.6. </span><span class="content">A writable stream with no backpressure or success signals</span><a class="self-link" href="#example-ws-no-backpressure"></a></h3>
    <p>The following function returns a <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①⑧">writable stream</a> that wraps a <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/web-sockets.html#websocket" id="ref-for-websocket①">WebSocket</a></code> <a data-link-type="biblio" href="#biblio-html">[HTML]</a>. Web sockets do not provide
any way to tell when a given chunk of data has been successfully sent (without awkward polling of <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/web-sockets.html#dom-websocket-bufferedamount" id="ref-for-dom-websocket-bufferedamount">bufferedAmount</a></code>, which we leave as an exercise to the reader). As such, this writable stream has no ability
to communicate accurate <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure②②">backpressure</a> signals or write success/failure to its <a data-link-type="dfn" href="#producer" id="ref-for-producer⑧">producers</a>. That is, the
promises returned by its <a data-link-type="dfn" href="#writer" id="ref-for-writer⑥">writer</a>’s <code class="idl"><a data-link-type="idl" href="#default-writer-write" id="ref-for-default-writer-write①②">write()</a></code> method and <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready⑧">ready</a></code> getter will always fulfill immediately.</p>
<pre><code class="lang-javascript highlight"><c- a>function</c-> makeWritableWebSocketStream<c- p>(</c->url<c- p>,</c-> protocols<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> ws <c- o>=</c-> <c- k>new</c-> WebSocket<c- p>(</c->url<c- p>,</c-> protocols<c- p>);</c->

  <c- k>return</c-> <c- k>new</c-> WritableStream<c- p>({</c->
    start<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
      ws<c- p>.</c->onerror <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> <c- p>{</c->
        controller<c- p>.</c->error<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The WebSocket errored!"</c-><c- p>));</c->
        ws<c- p>.</c->onclose <c- o>=</c-> <c- kc>null</c-><c- p>;</c->
      <c- p>};</c->
      ws<c- p>.</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> controller<c- p>.</c->error<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The server closed the connection unexpectedly!"</c-><c- p>));</c->
      <c- k>return</c-> <c- k>new</c-> Promise<c- p>(</c->resolve <c- p>=></c-> ws<c- p>.</c->onopen <c- o>=</c-> resolve<c- p>);</c->
    <c- p>},</c->

    write<c- p>(</c->chunk<c- p>)</c-> <c- p>{</c->
      ws<c- p>.</c->send<c- p>(</c->chunk<c- p>);</c->
      <c- c1>// Return immediately, since the web socket gives us no easy way to tell</c->
      <c- c1>// when the write completes.</c->
    <c- p>},</c->

    close<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> closeWS<c- p>(</c-><c- mi>1000</c-><c- p>);</c->
    <c- p>},</c->

    abort<c- p>(</c->reason<c- p>)</c-> <c- p>{</c->
      <c- k>return</c-> closeWS<c- p>(</c-><c- mi>4000</c-><c- p>,</c-> reason <c- o>&amp;&amp;</c-> reason<c- p>.</c->message<c- p>);</c->
    <c- p>},</c->
  <c- p>});</c->

  <c- a>function</c-> closeWS<c- p>(</c->code<c- p>,</c-> reasonString<c- p>)</c-> <c- p>{</c->
    <c- k>return</c-> <c- k>new</c-> Promise<c- p>((</c->resolve<c- p>,</c-> reject<c- p>)</c-> <c- p>=></c-> <c- p>{</c->
      ws<c- p>.</c->onclose <c- o>=</c-> e <c- p>=></c-> <c- p>{</c->
        <c- k>if</c-> <c- p>(</c->e<c- p>.</c->wasClean<c- p>)</c-> <c- p>{</c->
          resolve<c- p>();</c->
        <c- p>}</c-> <c- k>else</c-> <c- p>{</c->
          reject<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The connection was not closed cleanly"</c-><c- p>));</c->
        <c- p>}</c->
      <c- p>};</c->
      ws<c- p>.</c->close<c- p>(</c->code<c- p>,</c-> reasonString<c- p>);</c->
    <c- p>});</c->
  <c- p>}</c->
<c- p>}</c->
</code></pre>
    <p>We can then use this function to create writable streams for a web socket, and pipe an arbitrary readable stream to it:</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> webSocketStream <c- o>=</c-> makeWritableWebSocketStream<c- p>(</c-><c- u>"wss://example.com:443/"</c-><c- p>,</c-> <c- u>"protocol"</c-><c- p>);</c->

readableStream<c- p>.</c->pipeTo<c- p>(</c->webSocketStream<c- p>)</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"All data successfully written!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c-><c- u>"Something went wrong!"</c-><c- p>,</c-> e<c- p>));</c->
</code></pre>
    <p class="note" role="note">See <a href="#note-web-socket-wrapping-examples">the earlier note</a> about this style of wrapping web
sockets into streams.</p>
    <h3 class="heading settled" data-level="8.7" id="example-ws-backpressure"><span class="secno">8.7. </span><span class="content">A writable stream with backpressure and success signals</span><a class="self-link" href="#example-ws-backpressure"></a></h3>
    <p>The following function returns <a data-link-type="dfn" href="#writable-stream" id="ref-for-writable-stream①⑨">writable streams</a> that wrap portions of the <a href="https://nodejs.org/api/fs.html">Node.js file system API</a> (which themselves map fairly directly to C’s <code>fopen</code>, <code>fwrite</code>, and <code>fclose</code> trio). Since the API we are wrapping provides a way to
tell when a given write succeeds, this stream will be able to communicate <a data-link-type="dfn" href="#backpressure" id="ref-for-backpressure②③">backpressure</a> signals as well as whether
an individual write succeeded or failed.</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> fs <c- o>=</c-> require<c- p>(</c-><c- u>"pr/fs"</c-><c- p>);</c-> <c- c1>// https://github.com/jden/pr</c->

<c- a>function</c-> makeWritableFileStream<c- p>(</c->filename<c- p>)</c-> <c- p>{</c->
  <c- a>let</c-> fd<c- p>;</c->

  <c- k>return</c-> <c- k>new</c-> WritableStream<c- p>({</c->
    start<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->open<c- p>(</c->filename<c- p>,</c-> <c- u>"w"</c-><c- p>).</c->then<c- p>(</c->result <c- p>=></c-> <c- p>{</c->
        fd <c- o>=</c-> result<c- p>;</c->
      <c- p>});</c->
    <c- p>},</c->

    write<c- p>(</c->chunk<c- p>)</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->write<c- p>(</c->fd<c- p>,</c-> chunk<c- p>,</c-> <c- mi>0</c-><c- p>,</c-> chunk<c- p>.</c->length<c- p>);</c->
    <c- p>},</c->

    close<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->close<c- p>(</c->fd<c- p>);</c->
    <c- p>},</c->

    abort<c- p>()</c-> <c- p>{</c->
      <c- k>return</c-> fs<c- p>.</c->close<c- p>(</c->fd<c- p>);</c->
    <c- p>}</c->
  <c- p>});</c->
<c- p>}</c->
</code></pre>
    <p>We can then use this function to create a writable stream for a file, and write individual <a data-link-type="dfn" href="#chunk" id="ref-for-chunk⑦⑥">chunks</a> of data to it:</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> fileStream <c- o>=</c-> makeWritableFileStream<c- p>(</c-><c- u>"/example/path/on/fs.txt"</c-><c- p>);</c->
<c- kr>const</c-> writer <c- o>=</c-> fileStream<c- p>.</c->getWriter<c- p>();</c->

writer<c- p>.</c->write<c- p>(</c-><c- u>"To stream, or not to stream\n"</c-><c- p>);</c->
writer<c- p>.</c->write<c- p>(</c-><c- u>"That is the question\n"</c-><c- p>);</c->

writer<c- p>.</c->close<c- p>()</c->
  <c- p>.</c->then<c- p>(()</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c-><c- u>"chunks written and stream closed successfully!"</c-><c- p>))</c->
  <c- p>.</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c->e<c- p>));</c->
</code></pre>
    <p>Note that if a particular call to <code>fs.write</code> takes a longer time, the returned promise will fulfill later.
In the meantime, additional writes can be queued up, which are stored in the stream’s internal queue. The accumulation
of chunks in this queue can change the stream to return a pending promise from the <code class="idl"><a data-link-type="idl" href="#default-writer-ready" id="ref-for-default-writer-ready⑨">ready</a></code> getter, which is a signal to <a data-link-type="dfn" href="#producer" id="ref-for-producer⑨">producers</a> that they would benefit from backing off and stopping writing, if
possible.</p>
    <p>The way in which the writable stream queues up writes is especially important in this case, since as stated in <a href="https://nodejs.org/api/fs.html#fs_fs_write_fd_data_position_encoding_callback">the documentation for <code>fs.write</code></a>, "it is unsafe to use <code>fs.write</code> multiple times on the same file without waiting
for the [promise]." But we don’t have to worry about that when writing the <code>makeWritableFileStream</code> function, since the stream implementation guarantees that the <a data-link-type="dfn" href="#underlying-sink" id="ref-for-underlying-sink③①">underlying sink</a>’s <code class="idl"><a data-link-type="idl" href="#dom-underlying-sink-write" id="ref-for-dom-underlying-sink-write③">write()</a></code> method will not be called until any promises returned by previous calls have fulfilled!</p>
    <h3 class="heading settled" data-level="8.8" id="example-both"><span class="secno">8.8. </span><span class="content">A { readable, writable } stream pair wrapping the same underlying resource</span><a class="self-link" href="#example-both"></a></h3>
    <p>The following function returns an object of the form <code>{ readable, writable }</code>, with the <code>readable</code> property containing a readable stream and the <code>writable</code> property containing a
writable stream, where both streams wrap the same underlying web socket resource. In essence, this combines <a href="#example-rs-push-no-backpressure">§ 8.1 A readable stream with an underlying push source (no backpressure support)</a> and <a href="#example-ws-no-backpressure">§ 8.6 A writable stream with no backpressure or success signals</a>.</p>
    <p>While doing so, it illustrates how you can use JavaScript classes to create reusable underlying sink and underlying
source abstractions.</p>
<pre><code class="lang-javascript highlight"><c- a>function</c-> streamifyWebSocket<c- p>(</c->url<c- p>,</c-> protocol<c- p>)</c-> <c- p>{</c->
  <c- kr>const</c-> ws <c- o>=</c-> <c- k>new</c-> WebSocket<c- p>(</c->url<c- p>,</c-> protocols<c- p>);</c->
  ws<c- p>.</c->binaryType <c- o>=</c-> <c- u>"arraybuffer"</c-><c- p>;</c->

  <c- k>return</c-> <c- p>{</c->
    readable<c- o>:</c-> <c- k>new</c-> ReadableStream<c- p>(</c-><c- k>new</c-> WebSocketSource<c- p>(</c->ws<c- p>)),</c->
    writable<c- o>:</c-> <c- k>new</c-> WritableStream<c- p>(</c-><c- k>new</c-> WebSocketSink<c- p>(</c->ws<c- p>))</c->
  <c- p>};</c->
<c- p>}</c->

<c- kr>class</c-> WebSocketSource <c- p>{</c->
  constructor<c- p>(</c->ws<c- p>)</c-> <c- p>{</c->
    <c- k>this</c-><c- p>.</c->_ws <c- o>=</c-> ws<c- p>;</c->
  <c- p>}</c->

  start<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
    <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->onmessage <c- o>=</c-> event <c- p>=></c-> controller<c- p>.</c->enqueue<c- p>(</c->event<c- p>.</c->data<c- p>);</c->
    <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> controller<c- p>.</c->close<c- p>();</c->

    <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->addEventListener<c- p>(</c-><c- u>"error"</c-><c- p>,</c-> <c- p>()</c-> <c- p>=></c-> <c- p>{</c->
      controller<c- p>.</c->error<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The WebSocket errored!"</c-><c- p>));</c->
    <c- p>});</c->
  <c- p>}</c->

  cancel<c- p>()</c-> <c- p>{</c->
    <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->close<c- p>();</c->
  <c- p>}</c->
<c- p>}</c->

<c- kr>class</c-> WebSocketSink <c- p>{</c->
  constructor<c- p>(</c->ws<c- p>)</c-> <c- p>{</c->
    <c- k>this</c-><c- p>.</c->_ws <c- o>=</c-> ws<c- p>;</c->
  <c- p>}</c->

  start<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
    <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->onclose <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> controller<c- p>.</c->error<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The server closed the connection unexpectedly!"</c-><c- p>));</c->
    <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->addEventListener<c- p>(</c-><c- u>"error"</c-><c- p>,</c-> <c- p>()</c-> <c- p>=></c-> <c- p>{</c->
      controller<c- p>.</c->error<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The WebSocket errored!"</c-><c- p>));</c->
      <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->onclose <c- o>=</c-> <c- kc>null</c-><c- p>;</c->
    <c- p>});</c->

    <c- k>return</c-> <c- k>new</c-> Promise<c- p>(</c->resolve <c- p>=></c-> <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->onopen <c- o>=</c-> resolve<c- p>);</c->
  <c- p>}</c->

  write<c- p>(</c->chunk<c- p>)</c-> <c- p>{</c->
    <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->send<c- p>(</c->chunk<c- p>);</c->
  <c- p>}</c->

  close<c- p>()</c-> <c- p>{</c->
    <c- k>return</c-> <c- k>this</c-><c- p>.</c->_closeWS<c- p>(</c-><c- mi>1000</c-><c- p>);</c->
  <c- p>}</c->

  abort<c- p>(</c->reason<c- p>)</c-> <c- p>{</c->
    <c- k>return</c-> <c- k>this</c-><c- p>.</c->_closeWS<c- p>(</c-><c- mi>4000</c-><c- p>,</c-> reason <c- o>&amp;&amp;</c-> reason<c- p>.</c->message<c- p>);</c->
  <c- p>}</c->

  _closeWS<c- p>(</c->code<c- p>,</c-> reasonString<c- p>)</c-> <c- p>{</c->
    <c- k>return</c-> <c- k>new</c-> Promise<c- p>((</c->resolve<c- p>,</c-> reject<c- p>)</c-> <c- p>=></c-> <c- p>{</c->
      <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->onclose <c- o>=</c-> e <c- p>=></c-> <c- p>{</c->
        <c- k>if</c-> <c- p>(</c->e<c- p>.</c->wasClean<c- p>)</c-> <c- p>{</c->
          resolve<c- p>();</c->
        <c- p>}</c-> <c- k>else</c-> <c- p>{</c->
          reject<c- p>(</c-><c- k>new</c-> Error<c- p>(</c-><c- u>"The connection was not closed cleanly"</c-><c- p>));</c->
        <c- p>}</c->
      <c- p>};</c->
      <c- k>this</c-><c- p>.</c->_ws<c- p>.</c->close<c- p>(</c->code<c- p>,</c-> reasonString<c- p>);</c->
    <c- p>});</c->
  <c- p>}</c->
<c- p>}</c->
</code></pre>
    <p>We can then use the objects created by this function to communicate with a remote web socket, using the standard stream
APIs:</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> streamyWS <c- o>=</c-> streamifyWebSocket<c- p>(</c-><c- u>"wss://example.com:443/"</c-><c- p>,</c-> <c- u>"protocol"</c-><c- p>);</c->
<c- kr>const</c-> writer <c- o>=</c-> streamyWS<c- p>.</c->writable<c- p>.</c->getWriter<c- p>();</c->
<c- kr>const</c-> reader <c- o>=</c-> streamyWS<c- p>.</c->readable<c- p>.</c->getReader<c- p>();</c->

writer<c- p>.</c->write<c- p>(</c-><c- u>"Hello"</c-><c- p>);</c->
writer<c- p>.</c->write<c- p>(</c-><c- u>"web socket!"</c-><c- p>);</c->

reader<c- p>.</c->read<c- p>().</c->then<c- p>(({</c-> value<c- p>,</c-> done <c- p>})</c-> <c- p>=></c-> <c- p>{</c->
  console<c- p>.</c->log<c- p>(</c-><c- u>"The web socket says: "</c-><c- p>,</c-> value<c- p>);</c->
<c- p>});</c->
</code></pre>
    <p>Note how in this setup canceling the <code>readable</code> side will implicitly close the <code>writable</code> side,
and similarly, closing or aborting the <code>writable</code> side will implicitly close the <code>readable</code> side.</p>
    <p class="note" role="note">See <a href="#note-web-socket-wrapping-examples">the earlier note</a> about this style of wrapping web
sockets into streams.</p>
   </div>
   <h3 class="heading settled" data-level="8.9" id="example-ts-lipfuzz"><span class="secno">8.9. </span><span class="content">A transform stream that replaces template tags</span><a class="self-link" href="#example-ts-lipfuzz"></a></h3>
   <p>It’s often useful to substitute tags with variables on a stream of data, where the parts that need to be replaced are
small compared to the overall data size. This example presents a simple way to do that. It maps strings to strings,
transforming a template like <code>"Time: {{time}} Message: {{message}}"</code> to <code>"Time: 15:36 Message:
hello"</code> assuming that <code>{ time: "15:36", message: "hello" }</code> was passed in the <code>substitutions</code> parameter to <code>LipFuzzTransformer</code>.</p>
   <p>This example also demonstrates one way to deal with a situation where a chunk contains partial data that cannot be
transformed until more data is received. In this case, a partial template tag will be accumulated in the <code>partialChunk</code> instance variable until either the end of the tag is found or the end of the stream is
reached.</p>
<pre><code class="lang-javascript highlight"><c- kr>class</c-> LipFuzzTransformer <c- p>{</c->
  constructor<c- p>(</c->substitutions<c- p>)</c-> <c- p>{</c->
    <c- k>this</c-><c- p>.</c->substitutions <c- o>=</c-> substitutions<c- p>;</c->
    <c- k>this</c-><c- p>.</c->partialChunk <c- o>=</c-> <c- u>""</c-><c- p>;</c->
    <c- k>this</c-><c- p>.</c->lastIndex <c- o>=</c-> <c- kc>undefined</c-><c- p>;</c->
  <c- p>}</c->

  transform<c- p>(</c->chunk<c- p>,</c-> controller<c- p>)</c-> <c- p>{</c->
    chunk <c- o>=</c-> <c- k>this</c-><c- p>.</c->partialChunk <c- o>+</c-> chunk<c- p>;</c->
    <c- k>this</c-><c- p>.</c->partialChunk <c- o>=</c-> <c- u>""</c-><c- p>;</c->
    <c- c1>// lastIndex is the index of the first character after the last substitution.</c->
    <c- k>this</c-><c- p>.</c->lastIndex <c- o>=</c-> <c- mi>0</c-><c- p>;</c->
    chunk <c- o>=</c-> chunk<c- p>.</c->replace<c- p>(</c-><c- sr>/\{\{([a-zA-Z0-9_-]+)\}\}/g</c-><c- p>,</c-> <c- k>this</c-><c- p>.</c->replaceTag<c- p>.</c->bind<c- p>(</c-><c- k>this</c-><c- p>));</c->
    <c- c1>// Regular expression for an incomplete template at the end of a string.</c->
    <c- kr>const</c-> partialAtEndRegexp <c- o>=</c-> <c- sr>/\{(\{([a-zA-Z0-9_-]+(\})?)?)?$/g</c-><c- p>;</c->
    <c- c1>// Avoid looking at any characters that have already been substituted.</c->
    partialAtEndRegexp<c- p>.</c->lastIndex <c- o>=</c-> <c- k>this</c-><c- p>.</c->lastIndex<c- p>;</c->
    <c- k>this</c-><c- p>.</c->lastIndex <c- o>=</c-> <c- kc>undefined</c-><c- p>;</c->
    <c- kr>const</c-> match <c- o>=</c-> partialAtEndRegexp<c- p>.</c->exec<c- p>(</c->chunk<c- p>);</c->
    <c- k>if</c-> <c- p>(</c->match<c- p>)</c-> <c- p>{</c->
      <c- k>this</c-><c- p>.</c->partialChunk <c- o>=</c-> chunk<c- p>.</c->substring<c- p>(</c->match<c- p>.</c->index<c- p>);</c->
      chunk <c- o>=</c-> chunk<c- p>.</c->substring<c- p>(</c-><c- mi>0</c-><c- p>,</c-> match<c- p>.</c->index<c- p>);</c->
    <c- p>}</c->
    controller<c- p>.</c->enqueue<c- p>(</c->chunk<c- p>);</c->
  <c- p>}</c->

  flush<c- p>(</c->controller<c- p>)</c-> <c- p>{</c->
    <c- k>if</c-> <c- p>(</c-><c- k>this</c-><c- p>.</c->partialChunk<c- p>.</c->length <c- o>></c-> <c- mi>0</c-><c- p>)</c-> <c- p>{</c->
      controller<c- p>.</c->enqueue<c- p>(</c-><c- k>this</c-><c- p>.</c->partialChunk<c- p>);</c->
    <c- p>}</c->
  <c- p>}</c->

  replaceTag<c- p>(</c->match<c- p>,</c-> p1<c- p>,</c-> offset<c- p>)</c-> <c- p>{</c->
    <c- a>let</c-> replacement <c- o>=</c-> <c- k>this</c-><c- p>.</c->substitutions<c- p>[</c->p1<c- p>];</c->
    <c- k>if</c-> <c- p>(</c->replacement <c- o>===</c-> <c- kc>undefined</c-><c- p>)</c-> <c- p>{</c->
      replacement <c- o>=</c-> <c- u>""</c-><c- p>;</c->
    <c- p>}</c->
    <c- k>this</c-><c- p>.</c->lastIndex <c- o>=</c-> offset <c- o>+</c-> replacement<c- p>.</c->length<c- p>;</c->
    <c- k>return</c-> replacement<c- p>;</c->
  <c- p>}</c->
<c- p>}</c->
</code></pre>
   <p>In this case we define the <a data-link-type="dfn" href="#transformer" id="ref-for-transformer⑧">transformer</a> to be passed to the <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①④">TransformStream</a></code> constructor as a class. This is
useful when there is instance data to track.</p>
   <p>The class would be used in code like:</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> data <c- o>=</c-> <c- p>{</c-> userName<c- p>,</c-> displayName<c- p>,</c-> icon<c- p>,</c-> date <c- p>};</c->
<c- kr>const</c-> ts <c- o>=</c-> <c- k>new</c-> TransformStream<c- p>(</c-><c- k>new</c-> LipFuzzTransformer<c- p>(</c->data<c- p>));</c->

fetchEvent<c- p>.</c->respondWith<c- p>(</c->
  fetch<c- p>(</c->fetchEvent<c- p>.</c->request<c- p>.</c->url<c- p>).</c->then<c- p>(</c->response <c- p>=></c-> <c- p>{</c->
    <c- kr>const</c-> transformedBody <c- o>=</c-> response<c- p>.</c->body
      <c- c1>// Decode the binary-encoded response to string</c->
      <c- p>.</c->pipeThrough<c- p>(</c-><c- k>new</c-> TextDecoderStream<c- p>())</c->
      <c- c1>// Apply the LipFuzzTransformer</c->
      <c- p>.</c->pipeThrough<c- p>(</c->ts<c- p>)</c->
      <c- c1>// Encode the transformed string</c->
      <c- p>.</c->pipeThrough<c- p>(</c-><c- k>new</c-> TextEncoderStream<c- p>());</c->
    <c- k>return</c-> <c- k>new</c-> Response<c- p>(</c->transformedBody<c- p>);</c->
  <c- p>})</c->
<c- p>);</c->
</code></pre>
   <div class="warning">For simplicity, <code>LipFuzzTransformer</code> performs unescaped text substitutions. In real
applications, a template system that performs context-aware escaping is good practice for security and robustness.</div>
   <h3 class="heading settled" data-level="8.10" id="example-ts-sync-mapper"><span class="secno">8.10. </span><span class="content">A transform stream created from a sync mapper function</span><a class="self-link" href="#example-ts-sync-mapper"></a></h3>
   <p>The following function allows creating new <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①⑤">TransformStream</a></code> instances from synchronous "mapper" functions, of the
type you would normally pass to <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-array.prototype.map" id="ref-for-sec-array.prototype.map">Array.prototype.map</a></code>. It demonstrates that the API is concise
even for trivial transforms.</p>
<pre><code class="lang-javascript highlight"><c- a>function</c-> mapperTransformStream<c- p>(</c->mapperFunction<c- p>)</c-> <c- p>{</c->
  <c- k>return</c-> <c- k>new</c-> TransformStream<c- p>({</c->
    transform<c- p>(</c->chunk<c- p>,</c-> controller<c- p>)</c-> <c- p>{</c->
      controller<c- p>.</c->enqueue<c- p>(</c->mapperFunction<c- p>(</c->chunk<c- p>));</c->
    <c- p>}</c->
  <c- p>});</c->
<c- p>}</c->
</code></pre>
   <p>This function can then be used to create a <code class="idl"><a data-link-type="idl" href="#ts-class" id="ref-for-ts-class①⑥">TransformStream</a></code> that uppercases all its inputs:</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> ts <c- o>=</c-> mapperTransformStream<c- p>(</c->chunk <c- p>=></c-> chunk<c- p>.</c->toUpperCase<c- p>());</c->
<c- kr>const</c-> writer <c- o>=</c-> ts<c- p>.</c->writable<c- p>.</c->getWriter<c- p>();</c->
<c- kr>const</c-> reader <c- o>=</c-> ts<c- p>.</c->readable<c- p>.</c->getReader<c- p>();</c->

writer<c- p>.</c->write<c- p>(</c-><c- u>"No need to shout"</c-><c- p>);</c->

<c- c1>// Logs "NO NEED TO SHOUT":</c->
reader<c- p>.</c->read<c- p>().</c->then<c- p>(({</c-> value <c- p>})</c-> <c- p>=></c-> console<c- p>.</c->log<c- p>(</c->value<c- p>));</c->
</code></pre>
   <p>Although a synchronous transform never causes backpressure itself, it will only transform chunks as long as there is no
backpressure, so resources will not be wasted.</p>
   <p>Exceptions error the stream in a natural way:</p>
<pre><code class="lang-javascript highlight"><c- kr>const</c-> ts <c- o>=</c-> mapperTransformStream<c- p>(</c->chunk <c- p>=></c-> JSON<c- p>.</c->parse<c- p>(</c->chunk<c- p>));</c->
<c- kr>const</c-> writer <c- o>=</c-> ts<c- p>.</c->writable<c- p>.</c->getWriter<c- p>();</c->
<c- kr>const</c-> reader <c- o>=</c-> ts<c- p>.</c->readable<c- p>.</c->getReader<c- p>();</c->

writer<c- p>.</c->write<c- p>(</c-><c- u>"[1, "</c-><c- p>);</c->

<c- c1>// Logs a SyntaxError, twice:</c->
reader<c- p>.</c->read<c- p>().</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c->e<c- p>));</c->
writer<c- p>.</c->write<c- p>(</c-><c- u>"{}"</c-><c- p>).</c-><c- k>catch</c-><c- p>(</c->e <c- p>=></c-> console<c- p>.</c->error<c- p>(</c->e<c- p>));</c->
</code></pre>
   <h2 class="no-num heading settled" id="conventions"><span class="content">Conventions</span><a class="self-link" href="#conventions"></a></h2>
   <p>This specification depends on the Infra Standard. <a data-link-type="biblio" href="#biblio-infra">[INFRA]</a></p>
   <p>This specification uses algorithm conventions very similar to those of <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, whose rules should be used to
interpret it (apart from the exceptions enumerated below). In particular, the objects specified here should be treated
as <a href="https://tc39.github.io/ecma262/#sec-ecmascript-standard-built-in-objects">built-in objects</a>. For example,
their <code>name</code> and <code>length</code> properties are derived as described by that specification, as are the
default property descriptor values and the treatment of missing, <emu-val>undefined</emu-val>, or surplus arguments.</p>
   <p>We also depart from the <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a> conventions in the following ways, mostly for brevity. It is hoped (and vaguely
planned) that the conventions of ECMAScript itself will evolve in these ways.</p>
   <ul>
    <li> We prefix section headings with <code>new</code> to indicate they are defining constructors; when doing so, we
  assume that NewTarget will be checked before the algorithm starts. 
    <li> We use the default argument notation <code>= {}</code> in a couple of cases, meaning that before the algorithm
    starts, <emu-val>undefined</emu-val> (including the implicit <emu-val>undefined</emu-val> when no argument is
    provided) is instead treated as a new object created as if by ObjectCreate(%ObjectPrototype%). (This object may then
    be destructured, if combined with the below destructuring convention.) 
    <li> We use destructuring notation in function and method declarations, and assume that <a data-link-type="abstract-op" href="https://tc39.github.io/ecma262/#sec-runtime-semantics-destructuringassignmentevaluation" id="ref-for-sec-runtime-semantics-destructuringassignmentevaluation">DestructuringAssignmentEvaluation</a> was performed appropriately before the algorithm starts. 
    <li> We use "<emu-val>this</emu-val>" instead of "<emu-val>this</emu-val> value". 
   </ul>
   <p>It’s also worth noting that, as in <a data-link-type="biblio" href="#biblio-ecmascript">[ECMASCRIPT]</a>, all numbers are represented as double-precision floating point
values, and all arithmetic operations performed on them must be done in the standard way for such values.</p>
   <h2 class="no-num heading settled" id="acks"><span class="content">Acknowledgments</span><a class="self-link" href="#acks"></a></h2>
   <p>The editors would like to thank
Anne van Kesteren,
AnthumChris,
Arthur Langereis,
Ben Kelly,
Bert Belder,
Brian di Palma,
Calvin Metcalf,
Dominic Tarr,
Ed Hager,
Forbes Lindesay,
Forrest Norvell,
Gary Blackwood,
Gorgi Kosev,
Gus Caplan,
贺师俊 (hax),
Isaac Schlueter,
isonmad,
Jake Archibald,
Jake Verbaten,
Janessa Det,
Jason Orendorff,
Jens Nockert,
Lennart Grahl,
Mangala Sadhu Sangeet Singh Khalsa,
Marcos Caceres,
Marvin Hagemeister,
Mattias Buelens,
Michael Mior,
Mihai Potra,
Romain Bellessort, 
Simon Menke,
Stephen Sugden,
Surma,
Tab Atkins,
Tanguy Krotoff,
Thorsten Lorenz,
Till Schneidereit,
Tim Caswell,
Trevor Norris,
tzik,
Will Chan,
Youenn Fablet,
平野裕 (Yutaka Hirano),
and
Xabier Rodríguez
for their contributions to this specification. Community involvement in this specification has been above and beyond; we
couldn’t have done it without you.</p>
   <p>This standard is written by Adam Rice (<a href="https://google.com">Google</a>, <a href="mailto:ricea@chromium.org">ricea@chromium.org</a>), <a href="https://domenic.me/">Domenic Denicola</a> (<a href="https://google.com">Google</a>, <a href="mailto:d@domenic.me">d@domenic.me</a>), and 吉野剛史 (Takeshi Yoshino, <a href="https://google.com">Google</a>, <a href="mailto:tyoshino@chromium.org">tyoshino@chromium.org</a>).</p>
   <p>Copyright © 1970 WHATWG (Apple, Google, Mozilla, Microsoft). This work is licensed under a <a href="https://creativecommons.org/licenses/by/4.0/" rel="license">Creative Commons Attribution
4.0 International License</a>. </p>
  </main>
<script>
"use strict";
if ("serviceWorker" in navigator) {
  navigator.serviceWorker.register("/service-worker.js");
}
</script>
  <h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span><a class="self-link" href="#index"></a></h2>
  <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="content">Terms defined by this specification</span><a class="self-link" href="#index-defined-here"></a></h3>
  <ul class="index">
   <li><a href="#abort-a-writable-stream">abort a writable stream</a><span>, in §2.2</span>
   <li>
    abort(reason)
    <ul>
     <li><a href="#ws-abort">method for WritableStream</a><span>, in §4.2.5.1</span>
     <li><a href="#default-writer-abort">method for WritableStreamDefaultWriter</a><span>, in §4.5.4.3</span>
     <li><a href="#dom-underlying-sink-abort">method for underlying sink</a><span>, in §4.2.4</span>
    </ul>
   <li><a href="#active">active</a><span>, in §2.6</span>
   <li><a href="#active">active reader</a><span>, in §2.6</span>
   <li><a href="#active">active writer</a><span>, in §2.6</span>
   <li><a href="#rs-asynciterator">[@@asyncIterator]({ preventCancel } = {})</a><span>, in §3.2.5.7</span>
   <li><a href="#underlying-source-autoallocatechunksize">autoAllocateChunkSize</a><span>, in §3.2.4</span>
   <li><a href="#backpressure">backpressure</a><span>, in §2.4</span>
   <li><a href="#branches-of-a-readable-stream-tee">branches of a readable stream tee</a><span>, in §2.1</span>
   <li><a href="#byob-readers">BYOB readers</a><span>, in §2.6</span>
   <li><a href="#rbs-controller-byob-request">byobRequest</a><span>, in §3.11.4</span>
   <li><a href="#blqs-class">ByteLengthQueuingStrategy</a><span>, in §6.1.1</span>
   <li><a href="#blqs-constructor">ByteLengthQueuingStrategy(options)</a><span>, in §6.1.2.1</span>
   <li><a href="#cancel-a-readable-stream">cancel a readable stream</a><span>, in §2.1</span>
   <li>
    cancel(reason)
    <ul>
     <li><a href="#rs-cancel">method for ReadableStream</a><span>, in §3.2.5.1</span>
     <li><a href="#byob-reader-cancel">method for ReadableStreamBYOBReader</a><span>, in §3.7.4.1</span>
     <li><a href="#default-reader-cancel">method for ReadableStreamDefaultReader</a><span>, in §3.6.4.1</span>
     <li><a href="#dom-underlying-source-cancel">method for underlying source</a><span>, in §3.2.4</span>
    </ul>
   <li><a href="#abstract-opdef-cancelsteps">[[CancelSteps]]</a><span>, in §3.5</span>
   <li><a href="#chunk">chunk</a><span>, in §2</span>
   <li>
    close()
    <ul>
     <li><a href="#rbs-controller-close">method for ReadableByteStreamController</a><span>, in §3.11.4.2</span>
     <li><a href="#rs-default-controller-close">method for ReadableStreamDefaultController</a><span>, in §3.9.4.1</span>
     <li><a href="#ws-close">method for WritableStream</a><span>, in §4.2.5.2</span>
     <li><a href="#default-writer-close">method for WritableStreamDefaultWriter</a><span>, in §4.5.4.4</span>
     <li><a href="#dom-underlying-sink-close">method for underlying sink</a><span>, in §4.2.4</span>
    </ul>
   <li>
    closed
    <ul>
     <li><a href="#byob-reader-closed">attribute for ReadableStreamBYOBReader</a><span>, in §3.7.4</span>
     <li><a href="#default-reader-closed">attribute for ReadableStreamDefaultReader</a><span>, in §3.6.4</span>
     <li><a href="#default-writer-closed">attribute for WritableStreamDefaultWriter</a><span>, in §4.5.4</span>
    </ul>
   <li><a href="#consumer">consumer</a><span>, in §2.1</span>
   <li><a href="#cqs-class">CountQueuingStrategy</a><span>, in §6.1.2.3.1</span>
   <li><a href="#cqs-constructor">CountQueuingStrategy(options)</a><span>, in §6.1.3.1</span>
   <li><a href="#default-readers">default readers</a><span>, in §2.6</span>
   <li>
    desiredSize
    <ul>
     <li><a href="#rbs-controller-desired-size">attribute for ReadableByteStreamController</a><span>, in §3.11.4.1</span>
     <li><a href="#rs-default-controller-desired-size">attribute for ReadableStreamDefaultController</a><span>, in §3.9.4</span>
     <li><a href="#ts-default-controller-desired-size">attribute for TransformStreamDefaultController</a><span>, in §5.4.4</span>
     <li><a href="#default-writer-desired-size">attribute for WritableStreamDefaultWriter</a><span>, in §4.5.4.1</span>
    </ul>
   <li><a href="#desired-size-to-fill-a-streams-internal-queue">desired size to fill a stream’s internal queue</a><span>, in §2.5</span>
   <li>
    enqueue(chunk)
    <ul>
     <li><a href="#rbs-controller-enqueue">method for ReadableByteStreamController</a><span>, in §3.11.4.3</span>
     <li><a href="#rs-default-controller-enqueue">method for ReadableStreamDefaultController</a><span>, in §3.9.4.2</span>
     <li><a href="#ts-default-controller-enqueue">method for TransformStreamDefaultController</a><span>, in §5.4.4.1</span>
    </ul>
   <li>
    error(e)
    <ul>
     <li><a href="#rbs-controller-error">method for ReadableByteStreamController</a><span>, in §3.11.4.4</span>
     <li><a href="#rs-default-controller-error">method for ReadableStreamDefaultController</a><span>, in §3.9.4.3</span>
     <li><a href="#ws-default-controller-error">method for WritableStreamDefaultController</a><span>, in §4.7.4</span>
    </ul>
   <li><a href="#ts-default-controller-error">error(reason)</a><span>, in §5.4.4.2</span>
   <li><a href="#dom-transformer-flush">flush(controller)</a><span>, in §5.2.4</span>
   <li><a href="#rs-get-iterator">getIterator({ preventCancel } = {})</a><span>, in §3.2.5.2</span>
   <li><a href="#rs-get-reader">getReader({ mode } = {})</a><span>, in §3.2.5.3</span>
   <li><a href="#ws-get-writer">getWriter()</a><span>, in §4.2.5.3</span>
   <li><a href="#high-water-mark">high water mark</a><span>, in §2.5</span>
   <li><a href="#queuing-strategy-highwatermark">highWaterMark</a><span>, in §6.1.1</span>
   <li><a href="#identity-transform-stream">identity transform stream</a><span>, in §2.3</span>
   <li><a href="#internal-queues">internal queues</a><span>, in §2.5</span>
   <li><a href="#lock">lock</a><span>, in §2.6</span>
   <li>
    locked
    <ul>
     <li><a href="#rs-locked">attribute for ReadableStream</a><span>, in §3.2.5</span>
     <li><a href="#ws-locked">attribute for WritableStream</a><span>, in §4.2.5</span>
    </ul>
   <li><a href="#lock">locked to a reader</a><span>, in §2.6</span>
   <li><a href="#lock">locked to a writer</a><span>, in §2.6</span>
   <li><a href="#rs-asynciterator-prototype-next">next()</a><span>, in §3.3.1</span>
   <li><a href="#original-source">original source</a><span>, in §2.4</span>
   <li><a href="#pipe-chain">pipe chain</a><span>, in §2.4</span>
   <li><a href="#rs-pipe-through">pipeThrough(transform, options)</a><span>, in §3.2.5.4</span>
   <li><a href="#rs-pipe-to">pipeTo(dest, options)</a><span>, in §3.2.5.5</span>
   <li><a href="#piping">piping</a><span>, in §2.4</span>
   <li><a href="#producer">producer</a><span>, in §2.2</span>
   <li><a href="#dom-underlying-source-pull">pull(controller)</a><span>, in §3.2.4</span>
   <li><a href="#pull-source">pull source</a><span>, in §2.1</span>
   <li><a href="#abstract-opdef-pullsteps">[[PullSteps]]</a><span>, in §3.5</span>
   <li><a href="#push-source">push source</a><span>, in §2.1</span>
   <li><a href="#queuing-strategy">queuing strategy</a><span>, in §2.5</span>
   <li><a href="#default-reader-read">read()</a><span>, in §3.6.4.2</span>
   <li><a href="#ts-readable">readable</a><span>, in §5.2.5</span>
   <li><a href="#readable-byte-stream">readable byte stream</a><span>, in §2.1</span>
   <li><a href="#rbs-controller-constructor">ReadableByteStreamController()</a><span>, in §3.11.2</span>
   <li><a href="#rbs-controller-class">ReadableByteStreamController</a><span>, in §3.10.12</span>
   <li><a href="#readable-side">readable side</a><span>, in §2.3</span>
   <li><a href="#rs-class">ReadableStream</a><span>, in §3.1</span>
   <li><a href="#readable-stream">readable stream</a><span>, in §2.1</span>
   <li><a href="#rs-asynciterator-prototype">ReadableStreamAsyncIteratorPrototype</a><span>, in §3.2.5.8</span>
   <li><a href="#byob-reader-class">ReadableStreamBYOBReader</a><span>, in §3.6.4.4</span>
   <li><a href="#byob-reader-constructor">ReadableStreamBYOBReader(stream)</a><span>, in §3.7.2</span>
   <li><a href="#rs-byob-request-class">ReadableStreamBYOBRequest</a><span>, in §3.11.5.2</span>
   <li><a href="#rs-byob-request-constructor">ReadableStreamBYOBRequest(controller, view)</a><span>, in §3.12.2</span>
   <li><a href="#rs-default-controller-class">ReadableStreamDefaultController</a><span>, in §3.8.7</span>
   <li><a href="#rs-default-controller-constructor">ReadableStreamDefaultController()</a><span>, in §3.9.2</span>
   <li><a href="#default-reader-class">ReadableStreamDefaultReader</a><span>, in §3.5.12</span>
   <li><a href="#default-reader-constructor">ReadableStreamDefaultReader(stream)</a><span>, in §3.6.2</span>
   <li><a href="#reader">readable stream reader</a><span>, in §2.6</span>
   <li><a href="#rs-constructor">ReadableStream(underlyingSource, strategy)</a><span>, in §3.2.2</span>
   <li><a href="#reader">reader</a><span>, in §2.6</span>
   <li><a href="#byob-reader-read">read(view)</a><span>, in §3.7.4.2</span>
   <li><a href="#default-writer-ready">ready</a><span>, in §4.5.4.2</span>
   <li><a href="#release-a-lock">release a lock</a><span>, in §2.6</span>
   <li><a href="#release-a-lock">release a read lock</a><span>, in §2.6</span>
   <li><a href="#release-a-lock">release a write lock</a><span>, in §2.6</span>
   <li>
    releaseLock()
    <ul>
     <li><a href="#byob-reader-release-lock">method for ReadableStreamBYOBReader</a><span>, in §3.7.4.3</span>
     <li><a href="#default-reader-release-lock">method for ReadableStreamDefaultReader</a><span>, in §3.6.4.3</span>
     <li><a href="#default-writer-release-lock">method for WritableStreamDefaultWriter</a><span>, in §4.5.4.5</span>
    </ul>
   <li><a href="#rs-byob-request-respond">respond(bytesWritten)</a><span>, in §3.12.4.1</span>
   <li><a href="#rs-byob-request-respond-with-new-view">respondWithNewView(view)</a><span>, in §3.12.4.2</span>
   <li><a href="#rs-asynciterator-prototype-return">return(value)</a><span>, in §3.3.2</span>
   <li><a href="#cqs-size">size()</a><span>, in §6.1.3.3</span>
   <li>
    size(chunk)
    <ul>
     <li><a href="#blqs-size">method for ByteLengthQueuingStrategy</a><span>, in §6.1.2.3</span>
     <li><a href="#dom-queuing-strategy-size">method for queuing strategy</a><span>, in §6.1.1</span>
    </ul>
   <li>
    start(controller)
    <ul>
     <li><a href="#dom-transformer-start">method for transformer</a><span>, in §5.2.4</span>
     <li><a href="#dom-underlying-sink-start">method for underlying sink</a><span>, in §4.2.4</span>
     <li><a href="#dom-underlying-source-start">method for underlying source</a><span>, in §3.2.4</span>
    </ul>
   <li><a href="#rs-tee">tee()</a><span>, in §3.2.5.6</span>
   <li><a href="#tee-a-readable-stream">tee a readable stream</a><span>, in §2.1</span>
   <li><a href="#ts-default-controller-terminate">terminate()</a><span>, in §5.4.4.3</span>
   <li><a href="#dom-transformer-transform">transform(chunk, controller)</a><span>, in §5.2.4</span>
   <li><a href="#transformer">transformer</a><span>, in §2.3</span>
   <li><a href="#transform-stream">transform stream</a><span>, in §2.3</span>
   <li><a href="#ts-class">TransformStream</a><span>, in §5.1</span>
   <li><a href="#ts-default-controller-class">TransformStreamDefaultController</a><span>, in §5.3.6</span>
   <li><a href="#ts-default-controller-constructor">TransformStreamDefaultController()</a><span>, in §5.4.2</span>
   <li><a href="#ts-constructor">TransformStream(transformer, writableStrategy, readableStrategy)</a><span>, in §5.2.2</span>
   <li><a href="#underlying-source-type">type</a><span>, in §3.2.4</span>
   <li><a href="#ultimate-sink">ultimate sink</a><span>, in §2.4</span>
   <li><a href="#underlying-byte-source">underlying byte source</a><span>, in §2.1</span>
   <li><a href="#underlying-sink">underlying sink</a><span>, in §2.2</span>
   <li><a href="#underlying-source">underlying source</a><span>, in §2.1</span>
   <li><a href="#rs-byob-request-view">view</a><span>, in §3.12.4</span>
   <li><a href="#ts-writable">writable</a><span>, in §5.2.5.1</span>
   <li><a href="#writable-side">writable side</a><span>, in §2.3</span>
   <li><a href="#ws-class">WritableStream</a><span>, in §4.1</span>
   <li><a href="#writable-stream">writable stream</a><span>, in §2.2</span>
   <li><a href="#ws-default-controller-class">WritableStreamDefaultController</a><span>, in §4.6.9</span>
   <li><a href="#ws-default-controller-constructor">WritableStreamDefaultController()</a><span>, in §4.7.2</span>
   <li><a href="#default-writer-class">WritableStreamDefaultWriter</a><span>, in §4.4.14</span>
   <li><a href="#default-writer-constructor">WritableStreamDefaultWriter(stream)</a><span>, in §4.5.2</span>
   <li><a href="#ws-constructor">WritableStream(underlyingSink, strategy)</a><span>, in §4.2.2</span>
   <li><a href="#writer">writable stream writer</a><span>, in §2.6</span>
   <li><a href="#default-writer-write">write(chunk)</a><span>, in §4.5.4.6</span>
   <li><a href="#dom-underlying-sink-write">write(chunk, controller)</a><span>, in §4.2.4</span>
   <li><a href="#writer">writer</a><span>, in §2.6</span>
  </ul>
  <aside class="dfn-panel" data-for="term-for-abortcontroller">
   <a href="https://dom.spec.whatwg.org/#abortcontroller">https://dom.spec.whatwg.org/#abortcontroller</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abortcontroller">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-abortsignal">
   <a href="https://dom.spec.whatwg.org/#abortsignal">https://dom.spec.whatwg.org/#abortsignal</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abortsignal">3.2.5.5. pipeThrough({
writable, readable }, { preventClose, preventAbort,
preventCancel, signal } = {})</a>
    <li><a href="#ref-for-abortsignal①">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a> <a href="#ref-for-abortsignal②">(2)</a>
    <li><a href="#ref-for-abortsignal③">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-abortsignal-aborted-flag">
   <a href="https://dom.spec.whatwg.org/#abortsignal-aborted-flag">https://dom.spec.whatwg.org/#abortsignal-aborted-flag</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abortsignal-aborted-flag">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-abortsignal-add">
   <a href="https://dom.spec.whatwg.org/#abortsignal-add">https://dom.spec.whatwg.org/#abortsignal-add</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abortsignal-add">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-abortsignal-remove">
   <a href="https://dom.spec.whatwg.org/#abortsignal-remove">https://dom.spec.whatwg.org/#abortsignal-remove</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abortsignal-remove">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-asynciteratorprototype">
   <a href="https://tc39.github.io/ecma262/#sec-asynciteratorprototype">https://tc39.github.io/ecma262/#sec-asynciteratorprototype</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-asynciteratorprototype">3.3. ReadableStreamAsyncIteratorPrototype</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-typedarray-objects">
   <a href="https://tc39.github.io/ecma262/#sec-typedarray-objects">https://tc39.github.io/ecma262/#sec-typedarray-objects</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-typedarray-objects">2. Model</a>
    <li><a href="#ref-for-sec-typedarray-objects①">3.1. Using readable streams</a>
    <li><a href="#ref-for-sec-typedarray-objects②">3.11.4.1. get byobRequest</a>
    <li><a href="#ref-for-sec-typedarray-objects③">3.11.5.2. [[PullSteps]]( )</a> <a href="#ref-for-sec-typedarray-objects④">(2)</a>
    <li><a href="#ref-for-sec-typedarray-objects⑤">3.12.2. Internal slots</a>
    <li><a href="#ref-for-sec-typedarray-objects⑥">3.13.9. ReadableByteStreamControllerEnqueue ( controller, chunk )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-arraybuffer-objects">
   <a href="https://tc39.github.io/ecma262/#sec-arraybuffer-objects">https://tc39.github.io/ecma262/#sec-arraybuffer-objects</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-arraybuffer-objects">3.1. Using readable streams</a> <a href="#ref-for-sec-arraybuffer-objects①">(2)</a>
    <li><a href="#ref-for-sec-arraybuffer-objects②">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-sec-arraybuffer-objects③">6.3.6. TransferArrayBuffer ( O )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-asynciterator-interface">
   <a href="https://tc39.github.io/ecma262/#sec-asynciterator-interface">https://tc39.github.io/ecma262/#sec-asynciterator-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-asynciterator-interface">3.3. ReadableStreamAsyncIteratorPrototype</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-createiterresultobject">
   <a href="https://tc39.github.io/ecma262/#sec-createiterresultobject">https://tc39.github.io/ecma262/#sec-createiterresultobject</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-createiterresultobject">3.5.5. ReadableStreamCreateReadResult
( value, done, forAuthorCode )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-dataview-objects">
   <a href="https://tc39.github.io/ecma262/#sec-dataview-objects">https://tc39.github.io/ecma262/#sec-dataview-objects</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-dataview-objects">3.13.18. ReadableByteStreamControllerPullInto ( controller, view )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-runtime-semantics-destructuringassignmentevaluation">
   <a href="https://tc39.github.io/ecma262/#sec-runtime-semantics-destructuringassignmentevaluation">https://tc39.github.io/ecma262/#sec-runtime-semantics-destructuringassignmentevaluation</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-runtime-semantics-destructuringassignmentevaluation">Conventions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-invoke">
   <a href="https://tc39.github.io/ecma262/#sec-invoke">https://tc39.github.io/ecma262/#sec-invoke</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-invoke">6.3.2. InvokeOrNoop ( O, P, args
)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-ecmascript-language-types-number-type">
   <a href="https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type">https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-ecmascript-language-types-number-type">6.2. Queue-with-sizes operations</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-native-error-types-used-in-this-standard-typeerror">
   <a href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror">https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-native-error-types-used-in-this-standard-typeerror">4.2.4. Underlying sink API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-typedarray-objects">
   <a href="https://tc39.github.io/ecma262/#sec-typedarray-objects">https://tc39.github.io/ecma262/#sec-typedarray-objects</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-typedarray-objects">2. Model</a>
    <li><a href="#ref-for-sec-typedarray-objects①">3.1. Using readable streams</a>
    <li><a href="#ref-for-sec-typedarray-objects②">3.11.4.1. get byobRequest</a>
    <li><a href="#ref-for-sec-typedarray-objects③">3.11.5.2. [[PullSteps]]( )</a> <a href="#ref-for-sec-typedarray-objects④">(2)</a>
    <li><a href="#ref-for-sec-typedarray-objects⑤">3.12.2. Internal slots</a>
    <li><a href="#ref-for-sec-typedarray-objects⑥">3.13.9. ReadableByteStreamControllerEnqueue ( controller, chunk )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-array.prototype.map">
   <a href="https://tc39.github.io/ecma262/#sec-array.prototype.map">https://tc39.github.io/ecma262/#sec-array.prototype.map</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-array.prototype.map">8.10. A transform stream created from a sync mapper function</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-table-49">
   <a href="https://tc39.github.io/ecma262/#table-49">https://tc39.github.io/ecma262/#table-49</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-table-49">3.13.18. ReadableByteStreamControllerPullInto ( controller, view )</a> <a href="#ref-for-table-49①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-sec-typedarray-objects">
   <a href="https://tc39.github.io/ecma262/#sec-typedarray-objects">https://tc39.github.io/ecma262/#sec-typedarray-objects</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-sec-typedarray-objects">2. Model</a>
    <li><a href="#ref-for-sec-typedarray-objects①">3.1. Using readable streams</a>
    <li><a href="#ref-for-sec-typedarray-objects②">3.11.4.1. get byobRequest</a>
    <li><a href="#ref-for-sec-typedarray-objects③">3.11.5.2. [[PullSteps]]( )</a> <a href="#ref-for-sec-typedarray-objects④">(2)</a>
    <li><a href="#ref-for-sec-typedarray-objects⑤">3.12.2. Internal slots</a>
    <li><a href="#ref-for-sec-typedarray-objects⑥">3.13.9. ReadableByteStreamControllerEnqueue ( controller, chunk )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-response">
   <a href="https://fetch.spec.whatwg.org/#response">https://fetch.spec.whatwg.org/#response</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-response">1. Introduction</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-concept-request-body">
   <a href="https://fetch.spec.whatwg.org/#concept-request-body">https://fetch.spec.whatwg.org/#concept-request-body</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-concept-request-body">5.1. Using transform streams</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dom-global-fetch">
   <a href="https://fetch.spec.whatwg.org/#dom-global-fetch">https://fetch.spec.whatwg.org/#dom-global-fetch</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-global-fetch">5.1. Using transform streams</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-structureddeserialize">
   <a href="https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize">https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-structureddeserialize">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-structuredserialize">
   <a href="https://html.spec.whatwg.org/multipage/structured-data.html#structuredserialize">https://html.spec.whatwg.org/multipage/structured-data.html#structuredserialize</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-structuredserialize">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-websocket">
   <a href="https://html.spec.whatwg.org/multipage/web-sockets.html#websocket">https://html.spec.whatwg.org/multipage/web-sockets.html#websocket</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-websocket">8.1. A readable stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-websocket①">8.6. A writable stream with no backpressure or success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-dom-websocket-bufferedamount">
   <a href="https://html.spec.whatwg.org/multipage/web-sockets.html#dom-websocket-bufferedamount">https://html.spec.whatwg.org/multipage/web-sockets.html#dom-websocket-bufferedamount</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-websocket-bufferedamount">8.6. A writable stream with no backpressure or success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-the-img-element">
   <a href="https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element">https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-the-img-element">1. Introduction</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-in-parallel">
   <a href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-in-parallel">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-serializable-objects">
   <a href="https://html.spec.whatwg.org/multipage/structured-data.html#serializable-objects">https://html.spec.whatwg.org/multipage/structured-data.html#serializable-objects</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-serializable-objects">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-transferable-objects">
   <a href="https://html.spec.whatwg.org/multipage/structured-data.html#transferable-objects">https://html.spec.whatwg.org/multipage/structured-data.html#transferable-objects</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-transferable-objects">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-event-unhandledrejection">
   <a href="https://html.spec.whatwg.org/multipage/indices.html#event-unhandledrejection">https://html.spec.whatwg.org/multipage/indices.html#event-unhandledrejection</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-event-unhandledrejection">4.1. Using writable streams</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-set-append">
   <a href="https://infra.spec.whatwg.org/#set-append">https://infra.spec.whatwg.org/#set-append</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-set-append">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a> <a href="#ref-for-set-append①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-ordered-set">
   <a href="https://infra.spec.whatwg.org/#ordered-set">https://infra.spec.whatwg.org/#ordered-set</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ordered-set">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-a-new-promise">
   <a href="https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise">https://www.w3.org/2001/tag/doc/promises-guide/#a-new-promise</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-a-new-promise">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a>
    <li><a href="#ref-for-a-new-promise①">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
    <li><a href="#ref-for-a-new-promise②">3.5.1. ReadableStreamAddReadIntoRequest ( stream )</a>
    <li><a href="#ref-for-a-new-promise③">3.5.2. ReadableStreamAddReadRequest (
stream )</a>
    <li><a href="#ref-for-a-new-promise④">3.8.4. ReadableStreamReaderGenericInitialize ( reader, stream )</a>
    <li><a href="#ref-for-a-new-promise⑤">4.3.6. WritableStreamAbort ( stream,
reason )</a>
    <li><a href="#ref-for-a-new-promise⑥">4.3.7. WritableStreamClose ( stream )</a>
    <li><a href="#ref-for-a-new-promise⑦">4.4.1. WritableStreamAddWriteRequest (
stream )</a>
    <li><a href="#ref-for-a-new-promise⑧">4.4.14. WritableStreamUpdateBackpressure ( stream, backpressure )</a>
    <li><a href="#ref-for-a-new-promise⑨">4.5.3. new WritableStreamDefaultWriter(stream)</a> <a href="#ref-for-a-new-promise①⓪">(2)</a> <a href="#ref-for-a-new-promise①①">(3)</a>
    <li><a href="#ref-for-a-new-promise①②">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-a-new-promise①③">5.3.1. CreateTransformStream (
startAlgorithm, transformAlgorithm, flushAlgorithm
[, writableHighWaterMark [, writableSizeAlgorithm [, readableHighWaterMark [,
readableSizeAlgorithm ] ] ] ] )</a>
    <li><a href="#ref-for-a-new-promise①④">5.3.6. TransformStreamSetBackpressure
( stream, backpressure )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-a-promise-rejected-with">
   <a href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with">https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-rejected-with</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-a-promise-rejected-with">3.2.5.2. cancel(reason)</a> <a href="#ref-for-a-promise-rejected-with①">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with②">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a> <a href="#ref-for-a-promise-rejected-with③">(2)</a> <a href="#ref-for-a-promise-rejected-with④">(3)</a> <a href="#ref-for-a-promise-rejected-with⑤">(4)</a> <a href="#ref-for-a-promise-rejected-with⑥">(5)</a>
    <li><a href="#ref-for-a-promise-rejected-with⑦">3.3.2. next()</a> <a href="#ref-for-a-promise-rejected-with⑧">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with⑨">3.3.3. return( value )</a> <a href="#ref-for-a-promise-rejected-with①⓪">(2)</a> <a href="#ref-for-a-promise-rejected-with①①">(3)</a>
    <li><a href="#ref-for-a-promise-rejected-with①②">3.5.3. ReadableStreamCancel ( stream,
reason )</a>
    <li><a href="#ref-for-a-promise-rejected-with①③">3.6.4.1. get closed</a>
    <li><a href="#ref-for-a-promise-rejected-with①④">3.6.4.2. cancel(reason)</a> <a href="#ref-for-a-promise-rejected-with①⑤">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with①⑥">3.6.4.3. read()</a> <a href="#ref-for-a-promise-rejected-with①⑦">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with①⑧">3.7.4.1. get closed</a>
    <li><a href="#ref-for-a-promise-rejected-with①⑨">3.7.4.2. cancel(reason)</a> <a href="#ref-for-a-promise-rejected-with②⓪">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with②①">3.7.4.3. read(view)</a> <a href="#ref-for-a-promise-rejected-with②②">(2)</a> <a href="#ref-for-a-promise-rejected-with②③">(3)</a> <a href="#ref-for-a-promise-rejected-with②④">(4)</a> <a href="#ref-for-a-promise-rejected-with②⑤">(5)</a> <a href="#ref-for-a-promise-rejected-with②⑥">(6)</a>
    <li><a href="#ref-for-a-promise-rejected-with②⑦">3.8.4. ReadableStreamReaderGenericInitialize ( reader, stream )</a>
    <li><a href="#ref-for-a-promise-rejected-with②⑧">3.8.5. ReadableStreamReaderGenericRelease ( reader )</a>
    <li><a href="#ref-for-a-promise-rejected-with②⑨">3.8.6. ReadableStreamBYOBReaderRead
( reader, view )</a>
    <li><a href="#ref-for-a-promise-rejected-with③⓪">3.8.7. ReadableStreamDefaultReaderRead ( reader )</a>
    <li><a href="#ref-for-a-promise-rejected-with③①">3.11.5.2. [[PullSteps]]( )</a>
    <li><a href="#ref-for-a-promise-rejected-with③②">3.13.18. ReadableByteStreamControllerPullInto ( controller, view )</a>
    <li><a href="#ref-for-a-promise-rejected-with③③">4.2.5.2. abort(reason)</a> <a href="#ref-for-a-promise-rejected-with③④">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with③⑤">4.2.5.3. close()</a> <a href="#ref-for-a-promise-rejected-with③⑥">(2)</a> <a href="#ref-for-a-promise-rejected-with③⑦">(3)</a>
    <li><a href="#ref-for-a-promise-rejected-with③⑧">4.3.7. WritableStreamClose ( stream )</a>
    <li><a href="#ref-for-a-promise-rejected-with③⑨">4.5.3. new WritableStreamDefaultWriter(stream)</a> <a href="#ref-for-a-promise-rejected-with④⓪">(2)</a> <a href="#ref-for-a-promise-rejected-with④①">(3)</a>
    <li><a href="#ref-for-a-promise-rejected-with④②">4.5.4.1. get closed</a>
    <li><a href="#ref-for-a-promise-rejected-with④③">4.5.4.3. get ready</a>
    <li><a href="#ref-for-a-promise-rejected-with④④">4.5.4.4. abort(reason)</a> <a href="#ref-for-a-promise-rejected-with④⑤">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with④⑥">4.5.4.5. close()</a> <a href="#ref-for-a-promise-rejected-with④⑦">(2)</a> <a href="#ref-for-a-promise-rejected-with④⑧">(3)</a>
    <li><a href="#ref-for-a-promise-rejected-with④⑨">4.5.4.7. write(chunk)</a> <a href="#ref-for-a-promise-rejected-with⑤⓪">(2)</a>
    <li><a href="#ref-for-a-promise-rejected-with⑤①">4.6.4. WritableStreamDefaultWriterCloseWithErrorPropagation ( writer )</a>
    <li><a href="#ref-for-a-promise-rejected-with⑤②">4.6.5. WritableStreamDefaultWriterEnsureClosedPromiseRejected( writer, error )</a>
    <li><a href="#ref-for-a-promise-rejected-with⑤③">4.6.6. WritableStreamDefaultWriterEnsureReadyPromiseRejected( writer, error )</a>
    <li><a href="#ref-for-a-promise-rejected-with⑤④">4.6.9. WritableStreamDefaultWriterWrite ( writer, chunk )</a> <a href="#ref-for-a-promise-rejected-with⑤⑤">(2)</a> <a href="#ref-for-a-promise-rejected-with⑤⑥">(3)</a> <a href="#ref-for-a-promise-rejected-with⑤⑦">(4)</a>
    <li><a href="#ref-for-a-promise-rejected-with⑤⑧">5.5.3. SetUpTransformStreamDefaultControllerFromTransformer ( stream, transformer )</a>
    <li><a href="#ref-for-a-promise-rejected-with⑤⑨">6.3.5. PromiseCall ( F, V,
args )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-a-promise-resolved-with">
   <a href="https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with">https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-a-promise-resolved-with">3.3.3. return( value )</a>
    <li><a href="#ref-for-a-promise-resolved-with①">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a> <a href="#ref-for-a-promise-resolved-with②">(2)</a>
    <li><a href="#ref-for-a-promise-resolved-with③">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a> <a href="#ref-for-a-promise-resolved-with④">(2)</a>
    <li><a href="#ref-for-a-promise-resolved-with⑤">3.5.3. ReadableStreamCancel ( stream,
reason )</a>
    <li><a href="#ref-for-a-promise-resolved-with⑥">3.7.4.3. read(view)</a>
    <li><a href="#ref-for-a-promise-resolved-with⑦">3.8.4. ReadableStreamReaderGenericInitialize ( reader, stream )</a>
    <li><a href="#ref-for-a-promise-resolved-with⑧">3.8.7. ReadableStreamDefaultReaderRead ( reader )</a>
    <li><a href="#ref-for-a-promise-resolved-with⑨">3.9.5.2. [[PullSteps]]( )</a>
    <li><a href="#ref-for-a-promise-resolved-with①⓪">3.10.11. SetUpReadableStreamDefaultController(stream, controller, startAlgorithm,
pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-a-promise-resolved-with①①">3.11.5.2. [[PullSteps]]( )</a>
    <li><a href="#ref-for-a-promise-resolved-with①②">3.13.18. ReadableByteStreamControllerPullInto ( controller, view )</a> <a href="#ref-for-a-promise-resolved-with①③">(2)</a>
    <li><a href="#ref-for-a-promise-resolved-with①④">3.13.26. SetUpReadableByteStreamController ( stream, controller, startAlgorithm,
pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize )</a>
    <li><a href="#ref-for-a-promise-resolved-with①⑤">4.3.6. WritableStreamAbort ( stream,
reason )</a>
    <li><a href="#ref-for-a-promise-resolved-with①⑥">4.5.3. new WritableStreamDefaultWriter(stream)</a> <a href="#ref-for-a-promise-resolved-with①⑦">(2)</a> <a href="#ref-for-a-promise-resolved-with①⑧">(3)</a>
    <li><a href="#ref-for-a-promise-resolved-with①⑨">4.6.4. WritableStreamDefaultWriterCloseWithErrorPropagation ( writer )</a>
    <li><a href="#ref-for-a-promise-resolved-with②⓪">4.8.2. SetUpWritableStreamDefaultController ( stream, controller, startAlgorithm,
writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-a-promise-resolved-with②①">5.3.2. InitializeTransformStream (
stream, startPromise, writableHighWaterMark, writableSizeAlgorithm,
readableHighWaterMark, readableSizeAlgorithm )</a>
    <li><a href="#ref-for-a-promise-resolved-with②②">5.5.3. SetUpTransformStreamDefaultControllerFromTransformer ( stream, transformer )</a>
    <li><a href="#ref-for-a-promise-resolved-with②③">5.6.2. TransformStreamDefaultSinkAbortAlgorithm ( stream, reason )</a>
    <li><a href="#ref-for-a-promise-resolved-with②④">6.3.1. CreateAlgorithmFromUnderlyingMethod ( underlyingObject, methodName,
algoArgCount, extraArgs )</a>
    <li><a href="#ref-for-a-promise-resolved-with②⑤">6.3.5. PromiseCall ( F, V,
args )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-waiting-for-all-promise">
   <a href="https://www.w3.org/2001/tag/doc/promises-guide/#waiting-for-all-promise">https://www.w3.org/2001/tag/doc/promises-guide/#waiting-for-all-promise</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-waiting-for-all-promise">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-reject-promise">
   <a href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise">https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-reject-promise">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
    <li><a href="#ref-for-reject-promise①">3.5.6. ReadableStreamError ( stream, e
)</a> <a href="#ref-for-reject-promise②">(2)</a> <a href="#ref-for-reject-promise③">(3)</a>
    <li><a href="#ref-for-reject-promise④">3.8.5. ReadableStreamReaderGenericRelease ( reader )</a>
    <li><a href="#ref-for-reject-promise⑤">4.4.4. WritableStreamFinishErroring
( stream )</a> <a href="#ref-for-reject-promise⑥">(2)</a> <a href="#ref-for-reject-promise⑦">(3)</a>
    <li><a href="#ref-for-reject-promise⑧">4.4.6. WritableStreamFinishInFlightWriteWithError ( stream, error )</a>
    <li><a href="#ref-for-reject-promise⑨">4.4.8. WritableStreamFinishInFlightCloseWithError ( stream, error )</a> <a href="#ref-for-reject-promise①⓪">(2)</a>
    <li><a href="#ref-for-reject-promise①①">4.4.13. WritableStreamRejectCloseAndClosedPromiseIfNeeded (
stream )</a> <a href="#ref-for-reject-promise①②">(2)</a>
    <li><a href="#ref-for-reject-promise①③">4.6.5. WritableStreamDefaultWriterEnsureClosedPromiseRejected( writer, error )</a>
    <li><a href="#ref-for-reject-promise①④">4.6.6. WritableStreamDefaultWriterEnsureReadyPromiseRejected( writer, error )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-upon-fulfillment">
   <a href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment">https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-upon-fulfillment">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
    <li><a href="#ref-for-upon-fulfillment①">3.10.2. ReadableStreamDefaultControllerCallPullIfNeeded ( controller )</a>
    <li><a href="#ref-for-upon-fulfillment②">3.10.11. SetUpReadableStreamDefaultController(stream, controller, startAlgorithm,
pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-upon-fulfillment③">3.13.3. ReadableByteStreamControllerCallPullIfNeeded ( controller )</a>
    <li><a href="#ref-for-upon-fulfillment④">3.13.26. SetUpReadableByteStreamController ( stream, controller, startAlgorithm,
pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize )</a>
    <li><a href="#ref-for-upon-fulfillment⑤">4.4.4. WritableStreamFinishErroring
( stream )</a>
    <li><a href="#ref-for-upon-fulfillment⑥">4.8.2. SetUpWritableStreamDefaultController ( stream, controller, startAlgorithm,
writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-upon-fulfillment⑦">4.8.11. WritableStreamDefaultControllerProcessClose ( controller )</a>
    <li><a href="#ref-for-upon-fulfillment⑧">4.8.12. WritableStreamDefaultControllerProcessWrite ( controller, chunk )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-upon-rejection">
   <a href="https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection">https://www.w3.org/2001/tag/doc/promises-guide/#upon-rejection</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-upon-rejection">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a>
    <li><a href="#ref-for-upon-rejection①">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
    <li><a href="#ref-for-upon-rejection②">3.10.2. ReadableStreamDefaultControllerCallPullIfNeeded ( controller )</a>
    <li><a href="#ref-for-upon-rejection③">3.10.11. SetUpReadableStreamDefaultController(stream, controller, startAlgorithm,
pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-upon-rejection④">3.13.3. ReadableByteStreamControllerCallPullIfNeeded ( controller )</a>
    <li><a href="#ref-for-upon-rejection⑤">3.13.26. SetUpReadableByteStreamController ( stream, controller, startAlgorithm,
pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize )</a>
    <li><a href="#ref-for-upon-rejection⑥">4.4.4. WritableStreamFinishErroring
( stream )</a>
    <li><a href="#ref-for-upon-rejection⑦">4.8.2. SetUpWritableStreamDefaultController ( stream, controller, startAlgorithm,
writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-upon-rejection⑧">4.8.11. WritableStreamDefaultControllerProcessClose ( controller )</a>
    <li><a href="#ref-for-upon-rejection⑨">4.8.12. WritableStreamDefaultControllerProcessWrite ( controller, chunk )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-service-worker-global-scope-fetch-event">
   <a href="https://w3c.github.io/ServiceWorker/#service-worker-global-scope-fetch-event">https://w3c.github.io/ServiceWorker/#service-worker-global-scope-fetch-event</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-service-worker-global-scope-fetch-event">1. Introduction</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-aborterror">
   <a href="https://heycam.github.io/webidl/#aborterror">https://heycam.github.io/webidl/#aborterror</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-aborterror">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-idl-DOMException">
   <a href="https://heycam.github.io/webidl/#idl-DOMException">https://heycam.github.io/webidl/#idl-DOMException</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-idl-DOMException">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-call-a-user-objects-operation">
   <a href="https://heycam.github.io/webidl/#call-a-user-objects-operation">https://heycam.github.io/webidl/#call-a-user-objects-operation</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-call-a-user-objects-operation">6.3.5. PromiseCall ( F, V,
args )</a>
   </ul>
  </aside>
  <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span class="content">Terms defined by reference</span><a class="self-link" href="#index-defined-elsewhere"></a></h3>
  <ul class="index">
   <li>
    <a data-link-type="biblio">[DOM]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-abortcontroller" style="color:initial">AbortController</span>
     <li><span class="dfn-paneled" id="term-for-abortsignal" style="color:initial">AbortSignal</span>
     <li><span class="dfn-paneled" id="term-for-abortsignal-aborted-flag" style="color:initial">aborted flag</span>
     <li><span class="dfn-paneled" id="term-for-abortsignal-add" style="color:initial">add</span>
     <li><span class="dfn-paneled" id="term-for-abortsignal-remove" style="color:initial">remove</span>
    </ul>
   <li>
    <a data-link-type="biblio">[ECMASCRIPT]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-sec-asynciteratorprototype" style="color:initial">%AsyncIteratorPrototype%</span>
     <li><span class="dfn-paneled" id="term-for-sec-typedarray-objects" style="color:initial">%Uint8Array%</span>
     <li><span class="dfn-paneled" id="term-for-sec-arraybuffer-objects" style="color:initial">ArrayBuffer</span>
     <li><span class="dfn-paneled" id="term-for-sec-asynciterator-interface" style="color:initial">AsyncIterator</span>
     <li><span class="dfn-paneled" id="term-for-sec-createiterresultobject" style="color:initial">CreateIterResultObject</span>
     <li><span class="dfn-paneled" id="term-for-sec-dataview-objects" style="color:initial">DataView</span>
     <li><span class="dfn-paneled" id="term-for-sec-runtime-semantics-destructuringassignmentevaluation" style="color:initial">DestructuringAssignmentEvaluation</span>
     <li><span class="dfn-paneled" id="term-for-sec-invoke" style="color:initial">Invoke</span>
     <li><span class="dfn-paneled" id="term-for-sec-ecmascript-language-types-number-type" style="color:initial">Number</span>
     <li><span class="dfn-paneled" id="term-for-sec-native-error-types-used-in-this-standard-typeerror" style="color:initial">TypeError</span>
     <li><span class="dfn-paneled" id="term-for-sec-typedarray-objects①" style="color:initial">Uint8Array</span>
     <li><span class="dfn-paneled" id="term-for-sec-array.prototype.map" style="color:initial">map</span>
     <li><span class="dfn-paneled" id="term-for-table-49" style="color:initial">the typed array constructors table</span>
     <li><span class="dfn-paneled" id="term-for-sec-typedarray-objects②" style="color:initial">typed array</span>
    </ul>
   <li>
    <a data-link-type="biblio">[FETCH]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-response" style="color:initial">Response</span>
     <li><span class="dfn-paneled" id="term-for-concept-request-body" style="color:initial">body</span>
     <li><span class="dfn-paneled" id="term-for-dom-global-fetch" style="color:initial">fetch(input)</span>
    </ul>
   <li>
    <a data-link-type="biblio">[HTML]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-structureddeserialize" style="color:initial">StructuredDeserialize</span>
     <li><span class="dfn-paneled" id="term-for-structuredserialize" style="color:initial">StructuredSerialize</span>
     <li><span class="dfn-paneled" id="term-for-websocket" style="color:initial">WebSocket</span>
     <li><span class="dfn-paneled" id="term-for-dom-websocket-bufferedamount" style="color:initial">bufferedAmount</span>
     <li><span class="dfn-paneled" id="term-for-the-img-element" style="color:initial">img</span>
     <li><span class="dfn-paneled" id="term-for-in-parallel" style="color:initial">in parallel</span>
     <li><span class="dfn-paneled" id="term-for-serializable-objects" style="color:initial">serializable objects</span>
     <li><span class="dfn-paneled" id="term-for-transferable-objects" style="color:initial">transferable objects</span>
     <li><span class="dfn-paneled" id="term-for-event-unhandledrejection" style="color:initial">unhandledrejection</span>
    </ul>
   <li>
    <a data-link-type="biblio">[INFRA]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-set-append" style="color:initial">append</span>
     <li><span class="dfn-paneled" id="term-for-ordered-set" style="color:initial">ordered set</span>
    </ul>
   <li>
    <a data-link-type="biblio">[promises-guide]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-a-new-promise" style="color:initial">a new promise</span>
     <li><span class="dfn-paneled" id="term-for-a-promise-rejected-with" style="color:initial">a promise rejected with</span>
     <li><span class="dfn-paneled" id="term-for-a-promise-resolved-with" style="color:initial">a promise resolved with</span>
     <li><span class="dfn-paneled" id="term-for-waiting-for-all-promise" style="color:initial">getting a promise to wait for all</span>
     <li><span class="dfn-paneled" id="term-for-reject-promise" style="color:initial">reject</span>
     <li><span class="dfn-paneled" id="term-for-upon-fulfillment" style="color:initial">upon fulfillment</span>
     <li><span class="dfn-paneled" id="term-for-upon-rejection" style="color:initial">upon rejection</span>
    </ul>
   <li>
    <a data-link-type="biblio">[SERVICE-WORKERS]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-service-worker-global-scope-fetch-event" style="color:initial">fetch</span>
    </ul>
   <li>
    <a data-link-type="biblio">[WebIDL]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-aborterror" style="color:initial">AbortError</span>
     <li><span class="dfn-paneled" id="term-for-idl-DOMException" style="color:initial">DOMException</span>
     <li><span class="dfn-paneled" id="term-for-call-a-user-objects-operation" style="color:initial">call a user object's operation</span>
    </ul>
  </ul>
  <h2 class="no-num no-ref heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>
  <h3 class="no-num no-ref heading settled" id="normative"><span class="content">Normative References</span><a class="self-link" href="#normative"></a></h3>
  <dl>
   <dt id="biblio-dom">[DOM]
   <dd>Anne van Kesteren. <a href="https://dom.spec.whatwg.org/">DOM Standard</a>. Living Standard. URL: <a href="https://dom.spec.whatwg.org/">https://dom.spec.whatwg.org/</a>
   <dt id="biblio-ecmascript">[ECMASCRIPT]
   <dd><a href="https://tc39.github.io/ecma262/">ECMAScript Language Specification</a>. URL: <a href="https://tc39.github.io/ecma262/">https://tc39.github.io/ecma262/</a>
   <dt id="biblio-html">[HTML]
   <dd>Anne van Kesteren; et al. <a href="https://html.spec.whatwg.org/multipage/">HTML Standard</a>. Living Standard. URL: <a href="https://html.spec.whatwg.org/multipage/">https://html.spec.whatwg.org/multipage/</a>
   <dt id="biblio-infra">[INFRA]
   <dd>Anne van Kesteren; Domenic Denicola. <a href="https://infra.spec.whatwg.org/">Infra Standard</a>. Living Standard. URL: <a href="https://infra.spec.whatwg.org/">https://infra.spec.whatwg.org/</a>
   <dt id="biblio-promises-guide">[PROMISES-GUIDE]
   <dd>Domenic Denicola. <a href="https://www.w3.org/2001/tag/doc/promises-guide">Writing Promise-Using Specifications</a>. 9 November 2018. TAG Finding. URL: <a href="https://www.w3.org/2001/tag/doc/promises-guide">https://www.w3.org/2001/tag/doc/promises-guide</a>
   <dt id="biblio-webidl">[WebIDL]
   <dd>Boris Zbarsky. <a href="https://heycam.github.io/webidl/">Web IDL</a>. URL: <a href="https://heycam.github.io/webidl/">https://heycam.github.io/webidl/</a>
  </dl>
  <h3 class="no-num no-ref heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
  <dl>
   <dt id="biblio-fetch">[FETCH]
   <dd>Anne van Kesteren. <a href="https://fetch.spec.whatwg.org/">Fetch Standard</a>. Living Standard. URL: <a href="https://fetch.spec.whatwg.org/">https://fetch.spec.whatwg.org/</a>
   <dt id="biblio-service-workers">[SERVICE-WORKERS]
   <dd>Alex Russell; et al. <a href="https://w3c.github.io/ServiceWorker/">Service Workers 1</a>. URL: <a href="https://w3c.github.io/ServiceWorker/">https://w3c.github.io/ServiceWorker/</a>
  </dl>
  <aside class="dfn-panel" data-for="chunk">
   <b><a href="#chunk">#chunk</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-chunk">2.1. Readable streams</a> <a href="#ref-for-chunk①">(2)</a>
    <li><a href="#ref-for-chunk②">2.2. Writable streams</a>
    <li><a href="#ref-for-chunk③">2.3. Transform streams</a>
    <li><a href="#ref-for-chunk④">2.4. Pipe chains and backpressure</a> <a href="#ref-for-chunk⑤">(2)</a>
    <li><a href="#ref-for-chunk⑥">2.5. Internal queues and queuing strategies</a> <a href="#ref-for-chunk⑦">(2)</a> <a href="#ref-for-chunk⑧">(3)</a> <a href="#ref-for-chunk⑨">(4)</a>
    <li><a href="#ref-for-chunk①⓪">2.6. Locking</a> <a href="#ref-for-chunk①①">(2)</a>
    <li><a href="#ref-for-chunk①②">3.1. Using readable streams</a>
    <li><a href="#ref-for-chunk①③">3.2. Class ReadableStream</a>
    <li><a href="#ref-for-chunk①④">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-chunk①⑤">3.2.5.4. getReader({ mode } = {})</a> <a href="#ref-for-chunk①⑥">(2)</a> <a href="#ref-for-chunk①⑦">(3)</a>
    <li><a href="#ref-for-chunk①⑧">3.2.5.7. tee()</a>
    <li><a href="#ref-for-chunk①⑨">3.4.3. CreateReadableStream (
startAlgorithm, pullAlgorithm, cancelAlgorithm [, highWaterMark [,
sizeAlgorithm ] ] )</a>
    <li><a href="#ref-for-chunk②⓪">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a> <a href="#ref-for-chunk②①">(2)</a>
    <li><a href="#ref-for-chunk②②">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a> <a href="#ref-for-chunk②③">(2)</a> <a href="#ref-for-chunk②④">(3)</a> <a href="#ref-for-chunk②⑤">(4)</a> <a href="#ref-for-chunk②⑥">(5)</a> <a href="#ref-for-chunk②⑦">(6)</a> <a href="#ref-for-chunk②⑧">(7)</a> <a href="#ref-for-chunk②⑨">(8)</a>
    <li><a href="#ref-for-chunk③⓪">3.5. The interface between readable streams and controllers</a>
    <li><a href="#ref-for-chunk③①">3.6.2. Internal slots</a>
    <li><a href="#ref-for-chunk③②">3.6.4.3. read()</a>
    <li><a href="#ref-for-chunk③③">3.7.2. Internal slots</a>
    <li><a href="#ref-for-chunk③④">3.9.2. Internal slots</a> <a href="#ref-for-chunk③⑤">(2)</a> <a href="#ref-for-chunk③⑥">(3)</a>
    <li><a href="#ref-for-chunk③⑦">3.9.4.2. close()</a>
    <li><a href="#ref-for-chunk③⑧">3.9.4.3. enqueue(chunk)</a>
    <li><a href="#ref-for-chunk③⑨">3.10.6. ReadableStreamDefaultControllerEnqueue ( controller, chunk )</a>
    <li><a href="#ref-for-chunk④⓪">3.11.2. Internal slots</a> <a href="#ref-for-chunk④①">(2)</a>
    <li><a href="#ref-for-chunk④②">3.11.4.3. close()</a>
    <li><a href="#ref-for-chunk④③">3.11.4.4. enqueue(chunk)</a>
    <li><a href="#ref-for-chunk④④">4.1. Using writable streams</a>
    <li><a href="#ref-for-chunk④⑤">4.2.4. Underlying sink API</a> <a href="#ref-for-chunk④⑥">(2)</a>
    <li><a href="#ref-for-chunk④⑦">4.2.5.3. close()</a> <a href="#ref-for-chunk④⑧">(2)</a>
    <li><a href="#ref-for-chunk④⑨">4.3.2. CreateWritableStream ( startAlgorithm,
writeAlgorithm, closeAlgorithm, abortAlgorithm [, highWaterMark [,
sizeAlgorithm ] ] )</a>
    <li><a href="#ref-for-chunk⑤⓪">4.5.4.7. write(chunk)</a> <a href="#ref-for-chunk⑤①">(2)</a> <a href="#ref-for-chunk⑤②">(3)</a>
    <li><a href="#ref-for-chunk⑤③">4.7.2. Internal slots</a> <a href="#ref-for-chunk⑤④">(2)</a> <a href="#ref-for-chunk⑤⑤">(3)</a>
    <li><a href="#ref-for-chunk⑤⑥">5.1. Using transform streams</a>
    <li><a href="#ref-for-chunk⑤⑦">5.2.4. Transformer API</a> <a href="#ref-for-chunk⑤⑧">(2)</a> <a href="#ref-for-chunk⑤⑨">(3)</a> <a href="#ref-for-chunk⑥⓪">(4)</a>
    <li><a href="#ref-for-chunk⑥①">5.3.1. CreateTransformStream (
startAlgorithm, transformAlgorithm, flushAlgorithm
[, writableHighWaterMark [, writableSizeAlgorithm [, readableHighWaterMark [,
readableSizeAlgorithm ] ] ] ] )</a>
    <li><a href="#ref-for-chunk⑥②">5.4.2. Internal slots</a>
    <li><a href="#ref-for-chunk⑥③">5.4.4.2. enqueue(chunk)</a>
    <li><a href="#ref-for-chunk⑥④">5.4.4.3. error(reason)</a>
    <li><a href="#ref-for-chunk⑥⑤">5.4.4.4. terminate()</a>
    <li><a href="#ref-for-chunk⑥⑥">5.5.5. TransformStreamDefaultControllerEnqueue ( controller, chunk )</a>
    <li><a href="#ref-for-chunk⑥⑦">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-chunk⑥⑧">6.1.2. Class ByteLengthQueuingStrategy</a> <a href="#ref-for-chunk⑥⑨">(2)</a> <a href="#ref-for-chunk⑦⓪">(3)</a>
    <li><a href="#ref-for-chunk⑦①">6.1.3. Class CountQueuingStrategy</a> <a href="#ref-for-chunk⑦②">(2)</a>
    <li><a href="#ref-for-chunk⑦③">6.2. Queue-with-sizes operations</a>
    <li><a href="#ref-for-chunk⑦④">8.1. A readable stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-chunk⑦⑤">8.3. A readable byte stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-chunk⑦⑥">8.7. A writable stream with backpressure and success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="readable-stream">
   <b><a href="#readable-stream">#readable-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-readable-stream">1. Introduction</a>
    <li><a href="#ref-for-readable-stream①">2.1. Readable streams</a>
    <li><a href="#ref-for-readable-stream②">2.3. Transform streams</a>
    <li><a href="#ref-for-readable-stream③">2.6. Locking</a>
    <li><a href="#ref-for-readable-stream④">3.2. Class ReadableStream</a>
    <li><a href="#ref-for-readable-stream⑤">3.2.5.5. pipeThrough({
writable, readable }, { preventClose, preventAbort,
preventCancel, signal } = {})</a>
    <li><a href="#ref-for-readable-stream⑥">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a> <a href="#ref-for-readable-stream⑦">(2)</a> <a href="#ref-for-readable-stream⑧">(3)</a> <a href="#ref-for-readable-stream⑨">(4)</a> <a href="#ref-for-readable-stream①⓪">(5)</a> <a href="#ref-for-readable-stream①①">(6)</a>
    <li><a href="#ref-for-readable-stream①②">4.1. Using writable streams</a>
    <li><a href="#ref-for-readable-stream①③">5.1. Using transform streams</a> <a href="#ref-for-readable-stream①④">(2)</a> <a href="#ref-for-readable-stream①⑤">(3)</a>
    <li><a href="#ref-for-readable-stream①⑥">6.1.2. Class ByteLengthQueuingStrategy</a>
    <li><a href="#ref-for-readable-stream①⑦">6.1.3. Class CountQueuingStrategy</a>
    <li><a href="#ref-for-readable-stream①⑧">8.1. A readable stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-readable-stream①⑨">8.2. A readable stream with an underlying push source and backpressure support</a>
    <li><a href="#ref-for-readable-stream②⓪">8.4. A readable stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="underlying-source">
   <b><a href="#underlying-source">#underlying-source</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-underlying-source">2.1. Readable streams</a> <a href="#ref-for-underlying-source①">(2)</a> <a href="#ref-for-underlying-source②">(3)</a>
    <li><a href="#ref-for-underlying-source③">2.4. Pipe chains and backpressure</a> <a href="#ref-for-underlying-source④">(2)</a>
    <li><a href="#ref-for-underlying-source⑤">2.5. Internal queues and queuing strategies</a>
    <li><a href="#ref-for-underlying-source⑥">3.2. Class ReadableStream</a>
    <li><a href="#ref-for-underlying-source⑦">3.2.3. new
ReadableStream(underlyingSource = {}, strategy = {})</a>
    <li><a href="#ref-for-underlying-source⑧">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-underlying-source⑨">3.2.5.7. tee()</a>
    <li><a href="#ref-for-underlying-source①⓪">3.5. The interface between readable streams and controllers</a> <a href="#ref-for-underlying-source①①">(2)</a> <a href="#ref-for-underlying-source①②">(3)</a>
    <li><a href="#ref-for-underlying-source①③">3.6.4.3. read()</a>
    <li><a href="#ref-for-underlying-source①④">3.9. Class
ReadableStreamDefaultController</a>
    <li><a href="#ref-for-underlying-source①⑤">3.9.2. Internal slots</a> <a href="#ref-for-underlying-source①⑥">(2)</a> <a href="#ref-for-underlying-source①⑦">(3)</a> <a href="#ref-for-underlying-source①⑧">(4)</a> <a href="#ref-for-underlying-source①⑨">(5)</a> <a href="#ref-for-underlying-source②⓪">(6)</a> <a href="#ref-for-underlying-source②①">(7)</a>
    <li><a href="#ref-for-underlying-source②②">3.9.4.1. get
desiredSize</a>
    <li><a href="#ref-for-underlying-source②③">3.10.4. ReadableStreamDefaultControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-underlying-source②④">3.11.2. Internal slots</a> <a href="#ref-for-underlying-source②⑤">(2)</a> <a href="#ref-for-underlying-source②⑥">(3)</a>
    <li><a href="#ref-for-underlying-source②⑦">3.11.4.2. get desiredSize</a>
    <li><a href="#ref-for-underlying-source②⑧">3.13.4. ReadableByteStreamControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-underlying-source②⑨">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-underlying-source③⓪">6.1.2. Class ByteLengthQueuingStrategy</a>
    <li><a href="#ref-for-underlying-source③①">6.1.3. Class CountQueuingStrategy</a>
    <li><a href="#ref-for-underlying-source③②">8.2. A readable stream with an underlying push source and backpressure support</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="push-source">
   <b><a href="#push-source">#push-source</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-push-source">3.2.4. Underlying source API</a> <a href="#ref-for-push-source①">(2)</a>
    <li><a href="#ref-for-push-source②">8.1. A readable stream with an underlying push source (no backpressure support)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="pull-source">
   <b><a href="#pull-source">#pull-source</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-pull-source">3.2.4. Underlying source API</a> <a href="#ref-for-pull-source①">(2)</a>
    <li><a href="#ref-for-pull-source②">8.4. A readable stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="consumer">
   <b><a href="#consumer">#consumer</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-consumer">2.6. Locking</a>
    <li><a href="#ref-for-consumer①">3.2.4. Underlying source API</a> <a href="#ref-for-consumer②">(2)</a>
    <li><a href="#ref-for-consumer③">3.6.2. Internal slots</a>
    <li><a href="#ref-for-consumer④">3.7.2. Internal slots</a>
    <li><a href="#ref-for-consumer⑤">3.9.4.2. close()</a>
    <li><a href="#ref-for-consumer⑥">3.11.4.3. close()</a>
    <li><a href="#ref-for-consumer⑦">8.3. A readable byte stream with an underlying push source (no backpressure support)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="cancel-a-readable-stream">
   <b><a href="#cancel-a-readable-stream">#cancel-a-readable-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-cancel-a-readable-stream">2.6. Locking</a>
    <li><a href="#ref-for-cancel-a-readable-stream①">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-cancel-a-readable-stream②">3.2.5.2. cancel(reason)</a>
    <li><a href="#ref-for-cancel-a-readable-stream③">3.2.5.3. getIterator({ preventCancel } = {})</a>
    <li><a href="#ref-for-cancel-a-readable-stream④">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-cancel-a-readable-stream⑤">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a> <a href="#ref-for-cancel-a-readable-stream⑥">(2)</a> <a href="#ref-for-cancel-a-readable-stream⑦">(3)</a>
    <li><a href="#ref-for-cancel-a-readable-stream⑧">3.2.5.7. tee()</a>
    <li><a href="#ref-for-cancel-a-readable-stream⑨">3.3.1. Internal slots</a>
    <li><a href="#ref-for-cancel-a-readable-stream①⓪">3.5. The interface between readable streams and controllers</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="tee-a-readable-stream">
   <b><a href="#tee-a-readable-stream">#tee-a-readable-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-tee-a-readable-stream">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-tee-a-readable-stream①">3.1. Using readable streams</a>
    <li><a href="#ref-for-tee-a-readable-stream②">3.2.5.7. tee()</a>
    <li><a href="#ref-for-tee-a-readable-stream③">3.4.10. ReadableStreamTee ( stream,
cloneForBranch2 )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="branches-of-a-readable-stream-tee">
   <b><a href="#branches-of-a-readable-stream-tee">#branches-of-a-readable-stream-tee</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-branches-of-a-readable-stream-tee">2.4. Pipe chains and backpressure</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="underlying-byte-source">
   <b><a href="#underlying-byte-source">#underlying-byte-source</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-underlying-byte-source">3.5. The interface between readable streams and controllers</a>
    <li><a href="#ref-for-underlying-byte-source①">3.7.4.3. read(view)</a>
    <li><a href="#ref-for-underlying-byte-source②">3.11. Class
ReadableByteStreamController</a>
    <li><a href="#ref-for-underlying-byte-source③">3.11.2. Internal slots</a> <a href="#ref-for-underlying-byte-source④">(2)</a> <a href="#ref-for-underlying-byte-source⑤">(3)</a> <a href="#ref-for-underlying-byte-source⑥">(4)</a>
    <li><a href="#ref-for-underlying-byte-source⑦">8.5. A readable byte stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="readable-byte-stream">
   <b><a href="#readable-byte-stream">#readable-byte-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-readable-byte-stream">2.6. Locking</a>
    <li><a href="#ref-for-readable-byte-stream①">3.1. Using readable streams</a>
    <li><a href="#ref-for-readable-byte-stream②">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-readable-byte-stream③">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-readable-byte-stream④">3.5. The interface between readable streams and controllers</a>
    <li><a href="#ref-for-readable-byte-stream⑤">3.9. Class
ReadableStreamDefaultController</a>
    <li><a href="#ref-for-readable-byte-stream⑥">4.4. Writable stream abstract operations used by controllers</a>
    <li><a href="#ref-for-readable-byte-stream⑦">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-readable-byte-stream⑧">6.1.2. Class ByteLengthQueuingStrategy</a>
    <li><a href="#ref-for-readable-byte-stream⑨">8.3. A readable byte stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-readable-byte-stream①⓪">8.5. A readable byte stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="writable-stream">
   <b><a href="#writable-stream">#writable-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-writable-stream">1. Introduction</a>
    <li><a href="#ref-for-writable-stream①">2.3. Transform streams</a>
    <li><a href="#ref-for-writable-stream②">2.6. Locking</a>
    <li><a href="#ref-for-writable-stream③">3.1. Using readable streams</a> <a href="#ref-for-writable-stream④">(2)</a>
    <li><a href="#ref-for-writable-stream⑤">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a> <a href="#ref-for-writable-stream⑥">(2)</a> <a href="#ref-for-writable-stream⑦">(3)</a> <a href="#ref-for-writable-stream⑧">(4)</a> <a href="#ref-for-writable-stream⑨">(5)</a> <a href="#ref-for-writable-stream①⓪">(6)</a>
    <li><a href="#ref-for-writable-stream①①">4.4. Writable stream abstract operations used by controllers</a>
    <li><a href="#ref-for-writable-stream①②">5.1. Using transform streams</a> <a href="#ref-for-writable-stream①③">(2)</a> <a href="#ref-for-writable-stream①④">(3)</a>
    <li><a href="#ref-for-writable-stream①⑤">6.1.2. Class ByteLengthQueuingStrategy</a>
    <li><a href="#ref-for-writable-stream①⑥">6.1.3. Class CountQueuingStrategy</a>
    <li><a href="#ref-for-writable-stream①⑦">8.1. A readable stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-writable-stream①⑧">8.6. A writable stream with no backpressure or success signals</a>
    <li><a href="#ref-for-writable-stream①⑨">8.7. A writable stream with backpressure and success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="underlying-sink">
   <b><a href="#underlying-sink">#underlying-sink</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-underlying-sink">2.2. Writable streams</a> <a href="#ref-for-underlying-sink①">(2)</a>
    <li><a href="#ref-for-underlying-sink②">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-underlying-sink③">2.5. Internal queues and queuing strategies</a>
    <li><a href="#ref-for-underlying-sink④">4.1. Using writable streams</a> <a href="#ref-for-underlying-sink⑤">(2)</a> <a href="#ref-for-underlying-sink⑥">(3)</a>
    <li><a href="#ref-for-underlying-sink⑦">4.2.2. Internal slots</a> <a href="#ref-for-underlying-sink⑧">(2)</a> <a href="#ref-for-underlying-sink⑨">(3)</a>
    <li><a href="#ref-for-underlying-sink①⓪">4.2.3. new
WritableStream(underlyingSink = {}, strategy = {})</a>
    <li><a href="#ref-for-underlying-sink①①">4.2.4. Underlying sink API</a> <a href="#ref-for-underlying-sink①②">(2)</a> <a href="#ref-for-underlying-sink①③">(3)</a> <a href="#ref-for-underlying-sink①④">(4)</a> <a href="#ref-for-underlying-sink①⑤">(5)</a>
    <li><a href="#ref-for-underlying-sink①⑥">4.2.5.2. abort(reason)</a>
    <li><a href="#ref-for-underlying-sink①⑦">4.2.5.3. close()</a>
    <li><a href="#ref-for-underlying-sink①⑧">4.5.4.7. write(chunk)</a> <a href="#ref-for-underlying-sink①⑨">(2)</a>
    <li><a href="#ref-for-underlying-sink②⓪">4.7. Class
WritableStreamDefaultController</a>
    <li><a href="#ref-for-underlying-sink②①">4.7.2. Internal slots</a> <a href="#ref-for-underlying-sink②②">(2)</a> <a href="#ref-for-underlying-sink②③">(3)</a> <a href="#ref-for-underlying-sink②④">(4)</a> <a href="#ref-for-underlying-sink②⑤">(5)</a>
    <li><a href="#ref-for-underlying-sink②⑥">4.7.4.1. error(e)</a> <a href="#ref-for-underlying-sink②⑦">(2)</a>
    <li><a href="#ref-for-underlying-sink②⑧">4.8.4. WritableStreamDefaultControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-underlying-sink②⑨">6.1.2. Class ByteLengthQueuingStrategy</a>
    <li><a href="#ref-for-underlying-sink③⓪">6.1.3. Class CountQueuingStrategy</a>
    <li><a href="#ref-for-underlying-sink③①">8.7. A writable stream with backpressure and success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="producer">
   <b><a href="#producer">#producer</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-producer">2.6. Locking</a>
    <li><a href="#ref-for-producer①">4.1. Using writable streams</a>
    <li><a href="#ref-for-producer②">4.2.4. Underlying sink API</a> <a href="#ref-for-producer③">(2)</a>
    <li><a href="#ref-for-producer④">4.5.4.2. get desiredSize</a>
    <li><a href="#ref-for-producer⑤">4.5.4.6. releaseLock()</a>
    <li><a href="#ref-for-producer⑥">6.1.2. Class ByteLengthQueuingStrategy</a>
    <li><a href="#ref-for-producer⑦">6.1.3. Class CountQueuingStrategy</a>
    <li><a href="#ref-for-producer⑧">8.6. A writable stream with no backpressure or success signals</a>
    <li><a href="#ref-for-producer⑨">8.7. A writable stream with backpressure and success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="abort-a-writable-stream">
   <b><a href="#abort-a-writable-stream">#abort-a-writable-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abort-a-writable-stream">2.6. Locking</a>
    <li><a href="#ref-for-abort-a-writable-stream①">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a> <a href="#ref-for-abort-a-writable-stream②">(2)</a>
    <li><a href="#ref-for-abort-a-writable-stream③">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-abort-a-writable-stream④">4.2.5.2. abort(reason)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="transform-stream">
   <b><a href="#transform-stream">#transform-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-transform-stream">1. Introduction</a>
    <li><a href="#ref-for-transform-stream①">3.2.5.5. pipeThrough({
writable, readable }, { preventClose, preventAbort,
preventCancel, signal } = {})</a>
    <li><a href="#ref-for-transform-stream②">5.4.4.3. error(reason)</a>
    <li><a href="#ref-for-transform-stream③">5.4.4.4. terminate()</a>
    <li><a href="#ref-for-transform-stream④">8.1. A readable stream with an underlying push source (no backpressure support)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="writable-side">
   <b><a href="#writable-side">#writable-side</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-writable-side">2.3. Transform streams</a>
    <li><a href="#ref-for-writable-side①">5.1. Using transform streams</a>
    <li><a href="#ref-for-writable-side②">5.2.4. Transformer API</a> <a href="#ref-for-writable-side③">(2)</a> <a href="#ref-for-writable-side④">(3)</a>
    <li><a href="#ref-for-writable-side⑤">5.2.5.2. get writable</a>
    <li><a href="#ref-for-writable-side⑥">5.4.4.3. error(reason)</a>
    <li><a href="#ref-for-writable-side⑦">5.4.4.4. terminate()</a> <a href="#ref-for-writable-side⑧">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="readable-side">
   <b><a href="#readable-side">#readable-side</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-readable-side">2.3. Transform streams</a>
    <li><a href="#ref-for-readable-side①">5.1. Using transform streams</a>
    <li><a href="#ref-for-readable-side②">5.2.4. Transformer API</a> <a href="#ref-for-readable-side③">(2)</a> <a href="#ref-for-readable-side④">(3)</a> <a href="#ref-for-readable-side⑤">(4)</a>
    <li><a href="#ref-for-readable-side⑥">5.2.5.1. get readable</a>
    <li><a href="#ref-for-readable-side⑦">5.4.4.2. enqueue(chunk)</a>
    <li><a href="#ref-for-readable-side⑧">5.4.4.3. error(reason)</a>
    <li><a href="#ref-for-readable-side⑨">5.4.4.4. terminate()</a>
    <li><a href="#ref-for-readable-side①⓪">5.5.5. TransformStreamDefaultControllerEnqueue ( controller, chunk )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="transformer">
   <b><a href="#transformer">#transformer</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-transformer">2.3. Transform streams</a>
    <li><a href="#ref-for-transformer①">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-transformer②">5.2.4. Transformer API</a>
    <li><a href="#ref-for-transformer③">5.4. Class
TransformStreamDefaultController</a>
    <li><a href="#ref-for-transformer④">5.4.2. Internal slots</a> <a href="#ref-for-transformer⑤">(2)</a>
    <li><a href="#ref-for-transformer⑥">5.4.4.4. terminate()</a>
    <li><a href="#ref-for-transformer⑦">5.5.4. TransformStreamDefaultControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-transformer⑧">8.9. A transform stream that replaces template tags</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="identity-transform-stream">
   <b><a href="#identity-transform-stream">#identity-transform-stream</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-identity-transform-stream">5.1. Using transform streams</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="piping">
   <b><a href="#piping">#piping</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-piping">2.6. Locking</a> <a href="#ref-for-piping①">(2)</a>
    <li><a href="#ref-for-piping②">3.1. Using readable streams</a> <a href="#ref-for-piping③">(2)</a> <a href="#ref-for-piping④">(3)</a>
    <li><a href="#ref-for-piping⑤">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-piping⑥">3.2.5.5. pipeThrough({
writable, readable }, { preventClose, preventAbort,
preventCancel, signal } = {})</a>
    <li><a href="#ref-for-piping⑦">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a>
    <li><a href="#ref-for-piping⑧">4.1. Using writable streams</a>
    <li><a href="#ref-for-piping⑨">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-piping①⓪">5.1. Using transform streams</a> <a href="#ref-for-piping①①">(2)</a>
    <li><a href="#ref-for-piping①②">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-piping①③">8.1. A readable stream with an underlying push source (no backpressure support)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="pipe-chain">
   <b><a href="#pipe-chain">#pipe-chain</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-pipe-chain">1. Introduction</a>
    <li><a href="#ref-for-pipe-chain①">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-pipe-chain②">3.2.5.5. pipeThrough({
writable, readable }, { preventClose, preventAbort,
preventCancel, signal } = {})</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="original-source">
   <b><a href="#original-source">#original-source</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-original-source">2.4. Pipe chains and backpressure</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ultimate-sink">
   <b><a href="#ultimate-sink">#ultimate-sink</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ultimate-sink">2.4. Pipe chains and backpressure</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="backpressure">
   <b><a href="#backpressure">#backpressure</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-backpressure">1. Introduction</a>
    <li><a href="#ref-for-backpressure①">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-backpressure②">2.5. Internal queues and queuing strategies</a>
    <li><a href="#ref-for-backpressure③">3.1. Using readable streams</a> <a href="#ref-for-backpressure④">(2)</a>
    <li><a href="#ref-for-backpressure⑤">3.9.2. Internal slots</a>
    <li><a href="#ref-for-backpressure⑥">3.9.4.1. get
desiredSize</a>
    <li><a href="#ref-for-backpressure⑦">3.11.2. Internal slots</a>
    <li><a href="#ref-for-backpressure⑧">3.11.4.2. get desiredSize</a>
    <li><a href="#ref-for-backpressure⑨">4.1. Using writable streams</a> <a href="#ref-for-backpressure①⓪">(2)</a> <a href="#ref-for-backpressure①①">(3)</a>
    <li><a href="#ref-for-backpressure①②">4.5.4.3. get ready</a>
    <li><a href="#ref-for-backpressure①③">4.7.2. Internal slots</a>
    <li><a href="#ref-for-backpressure①④">5.1. Using transform streams</a>
    <li><a href="#ref-for-backpressure①⑤">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-backpressure①⑥">6.1.2. Class ByteLengthQueuingStrategy</a> <a href="#ref-for-backpressure①⑦">(2)</a>
    <li><a href="#ref-for-backpressure①⑧">6.1.3. Class CountQueuingStrategy</a> <a href="#ref-for-backpressure①⑨">(2)</a>
    <li><a href="#ref-for-backpressure②⓪">6.3.7. ValidateAndNormalizeHighWaterMark ( highWaterMark )</a>
    <li><a href="#ref-for-backpressure②①">8.2. A readable stream with an underlying push source and backpressure support</a>
    <li><a href="#ref-for-backpressure②②">8.6. A writable stream with no backpressure or success signals</a>
    <li><a href="#ref-for-backpressure②③">8.7. A writable stream with backpressure and success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="internal-queues">
   <b><a href="#internal-queues">#internal-queues</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-internal-queues">2.2. Writable streams</a>
    <li><a href="#ref-for-internal-queues①">2.5. Internal queues and queuing strategies</a>
    <li><a href="#ref-for-internal-queues②">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-internal-queues③">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
    <li><a href="#ref-for-internal-queues④">3.5. The interface between readable streams and controllers</a>
    <li><a href="#ref-for-internal-queues⑤">3.9. Class
ReadableStreamDefaultController</a>
    <li><a href="#ref-for-internal-queues⑥">3.11. Class
ReadableByteStreamController</a>
    <li><a href="#ref-for-internal-queues⑦">4.1. Using writable streams</a>
    <li><a href="#ref-for-internal-queues⑧">8.3. A readable byte stream with an underlying push source (no backpressure support)</a> <a href="#ref-for-internal-queues⑨">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="queuing-strategy">
   <b><a href="#queuing-strategy">#queuing-strategy</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-queuing-strategy">3.2.3. new
ReadableStream(underlyingSource = {}, strategy = {})</a>
    <li><a href="#ref-for-queuing-strategy①">3.9.2. Internal slots</a> <a href="#ref-for-queuing-strategy②">(2)</a>
    <li><a href="#ref-for-queuing-strategy③">3.11.2. Internal slots</a>
    <li><a href="#ref-for-queuing-strategy④">4.2.3. new
WritableStream(underlyingSink = {}, strategy = {})</a>
    <li><a href="#ref-for-queuing-strategy⑤">4.7.2. Internal slots</a> <a href="#ref-for-queuing-strategy⑥">(2)</a>
    <li><a href="#ref-for-queuing-strategy⑦">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-queuing-strategy⑧">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-queuing-strategy⑨">6.1.2. Class ByteLengthQueuingStrategy</a> <a href="#ref-for-queuing-strategy①⓪">(2)</a>
    <li><a href="#ref-for-queuing-strategy①①">6.1.3. Class CountQueuingStrategy</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="high-water-mark">
   <b><a href="#high-water-mark">#high-water-mark</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-high-water-mark">3.2.3. new
ReadableStream(underlyingSource = {}, strategy = {})</a>
    <li><a href="#ref-for-high-water-mark①">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-high-water-mark②">4.1. Using writable streams</a> <a href="#ref-for-high-water-mark③">(2)</a>
    <li><a href="#ref-for-high-water-mark④">4.2.3. new
WritableStream(underlyingSink = {}, strategy = {})</a>
    <li><a href="#ref-for-high-water-mark⑤">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-high-water-mark⑥">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-high-water-mark⑦">6.3.7. ValidateAndNormalizeHighWaterMark ( highWaterMark )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="desired-size-to-fill-a-streams-internal-queue">
   <b><a href="#desired-size-to-fill-a-streams-internal-queue">#desired-size-to-fill-a-streams-internal-queue</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue">3.2.4. Underlying source API</a> <a href="#ref-for-desired-size-to-fill-a-streams-internal-queue①">(2)</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue②">3.9.4.1. get
desiredSize</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue③">3.10.8. ReadableStreamDefaultControllerGetDesiredSize ( controller )</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue④">3.11.4.2. get desiredSize</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue⑤">4.1. Using writable streams</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue⑥">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue⑦">4.5.4.2. get desiredSize</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue⑧">4.5.4.3. get ready</a> <a href="#ref-for-desired-size-to-fill-a-streams-internal-queue⑨">(2)</a>
    <li><a href="#ref-for-desired-size-to-fill-a-streams-internal-queue①⓪">5.4.4.1. get
desiredSize</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="reader">
   <b><a href="#reader">#reader</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-reader">1. Introduction</a>
    <li><a href="#ref-for-reader①">2.1. Readable streams</a>
    <li><a href="#ref-for-reader②">3.1. Using readable streams</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-readers">
   <b><a href="#default-readers">#default-readers</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-readers">3.1. Using readable streams</a>
    <li><a href="#ref-for-default-readers①">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-default-readers②">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-default-readers③">3.4.2. AcquireReadableStreamDefaultReader ( stream[, forAuthorCode ] )</a>
    <li><a href="#ref-for-default-readers④">3.5. The interface between readable streams and controllers</a>
    <li><a href="#ref-for-default-readers⑤">3.6. Class
ReadableStreamDefaultReader</a>
    <li><a href="#ref-for-default-readers⑥">8.5. A readable byte stream with an underlying pull source</a> <a href="#ref-for-default-readers⑦">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="byob-readers">
   <b><a href="#byob-readers">#byob-readers</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-byob-readers">2.1. Readable streams</a>
    <li><a href="#ref-for-byob-readers①">3.1. Using readable streams</a>
    <li><a href="#ref-for-byob-readers②">3.2.4. Underlying source API</a> <a href="#ref-for-byob-readers③">(2)</a>
    <li><a href="#ref-for-byob-readers④">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-byob-readers⑤">3.4.1. AcquireReadableStreamBYOBReader ( stream[, forAuthorCode ] )</a>
    <li><a href="#ref-for-byob-readers⑥">3.4.11. ReadableStreamPipeTo (
source, dest, preventClose, preventAbort, preventCancel,
signal )</a>
    <li><a href="#ref-for-byob-readers⑦">3.7. Class ReadableStreamBYOBReader</a>
    <li><a href="#ref-for-byob-readers⑧">8.3. A readable byte stream with an underlying push source (no backpressure support)</a> <a href="#ref-for-byob-readers⑨">(2)</a> <a href="#ref-for-byob-readers①⓪">(3)</a>
    <li><a href="#ref-for-byob-readers①①">8.5. A readable byte stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="writer">
   <b><a href="#writer">#writer</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-writer">1. Introduction</a>
    <li><a href="#ref-for-writer①">4.1. Using writable streams</a> <a href="#ref-for-writer②">(2)</a>
    <li><a href="#ref-for-writer③">4.2.5.4. getWriter()</a>
    <li><a href="#ref-for-writer④">4.5. Class
WritableStreamDefaultWriter</a>
    <li><a href="#ref-for-writer⑤">5.1. Using transform streams</a>
    <li><a href="#ref-for-writer⑥">8.6. A writable stream with no backpressure or success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="lock">
   <b><a href="#lock">#lock</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-lock">2.1. Readable streams</a>
    <li><a href="#ref-for-lock①">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-lock②">3.2.2. Internal slots</a>
    <li><a href="#ref-for-lock③">3.2.5.1. get locked</a>
    <li><a href="#ref-for-lock④">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-lock⑤">3.2.5.5. pipeThrough({
writable, readable }, { preventClose, preventAbort,
preventCancel, signal } = {})</a>
    <li><a href="#ref-for-lock⑥">3.2.5.6. pipeTo(dest,
{ preventClose, preventAbort, preventCancel, signal } = {})</a>
    <li><a href="#ref-for-lock⑦">3.2.5.7. tee()</a>
    <li><a href="#ref-for-lock⑧">3.4.8. IsReadableStreamLocked (
stream )</a>
    <li><a href="#ref-for-lock⑨">4.2.2. Internal slots</a>
    <li><a href="#ref-for-lock①⓪">4.2.5.1. get locked</a>
    <li><a href="#ref-for-lock①①">4.2.5.4. getWriter()</a>
    <li><a href="#ref-for-lock①②">4.3.5. IsWritableStreamLocked ( stream
)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="active">
   <b><a href="#active">#active</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-active">3.6.4.2. cancel(reason)</a>
    <li><a href="#ref-for-active①">3.6.4.4. releaseLock()</a>
    <li><a href="#ref-for-active②">3.7.4.2. cancel(reason)</a>
    <li><a href="#ref-for-active③">3.7.4.4. releaseLock()</a>
    <li><a href="#ref-for-active④">4.5.4.4. abort(reason)</a>
    <li><a href="#ref-for-active⑤">4.5.4.5. close()</a>
    <li><a href="#ref-for-active⑥">4.5.4.6. releaseLock()</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="release-a-lock">
   <b><a href="#release-a-lock">#release-a-lock</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-release-a-lock">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-release-a-lock①">3.6.4.1. get closed</a>
    <li><a href="#ref-for-release-a-lock②">3.6.4.4. releaseLock()</a>
    <li><a href="#ref-for-release-a-lock③">3.7.4.1. get closed</a>
    <li><a href="#ref-for-release-a-lock④">3.7.4.4. releaseLock()</a>
    <li><a href="#ref-for-release-a-lock⑤">4.2.5.4. getWriter()</a>
    <li><a href="#ref-for-release-a-lock⑥">4.5.4.1. get closed</a>
    <li><a href="#ref-for-release-a-lock⑦">4.5.4.2. get desiredSize</a>
    <li><a href="#ref-for-release-a-lock⑧">4.5.4.3. get ready</a>
    <li><a href="#ref-for-release-a-lock⑨">4.5.4.6. releaseLock()</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-class">
   <b><a href="#rs-class">#rs-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-class">1. Introduction</a>
    <li><a href="#ref-for-rs-class①">2.1. Readable streams</a>
    <li><a href="#ref-for-rs-class②">3.2. Class ReadableStream</a>
    <li><a href="#ref-for-rs-class③">3.2.1. Class definition</a>
    <li><a href="#ref-for-rs-class④">3.2.2. Internal slots</a>
    <li><a href="#ref-for-rs-class⑤">3.2.4. Underlying source API</a> <a href="#ref-for-rs-class⑥">(2)</a> <a href="#ref-for-rs-class⑦">(3)</a>
    <li><a href="#ref-for-rs-class⑧">3.2.5. Properties of the ReadableStream prototype</a>
    <li><a href="#ref-for-rs-class⑨">3.2.5.7. tee()</a>
    <li><a href="#ref-for-rs-class①⓪">3.4.3. CreateReadableStream (
startAlgorithm, pullAlgorithm, cancelAlgorithm [, highWaterMark [,
sizeAlgorithm ] ] )</a> <a href="#ref-for-rs-class①①">(2)</a>
    <li><a href="#ref-for-rs-class①②">3.4.4. CreateReadableByteStream (
startAlgorithm, pullAlgorithm, cancelAlgorithm [, highWaterMark [,
autoAllocateChunkSize ] ] )</a> <a href="#ref-for-rs-class①③">(2)</a>
    <li><a href="#ref-for-rs-class①④">3.5. The interface between readable streams and controllers</a> <a href="#ref-for-rs-class①⑤">(2)</a> <a href="#ref-for-rs-class①⑥">(3)</a> <a href="#ref-for-rs-class①⑦">(4)</a> <a href="#ref-for-rs-class①⑧">(5)</a>
    <li><a href="#ref-for-rs-class①⑨">3.6. Class
ReadableStreamDefaultReader</a>
    <li><a href="#ref-for-rs-class②⓪">3.6.2. Internal slots</a>
    <li><a href="#ref-for-rs-class②①">3.7. Class ReadableStreamBYOBReader</a>
    <li><a href="#ref-for-rs-class②②">3.7.2. Internal slots</a>
    <li><a href="#ref-for-rs-class②③">3.9. Class
ReadableStreamDefaultController</a> <a href="#ref-for-rs-class②④">(2)</a>
    <li><a href="#ref-for-rs-class②⑤">3.9.2. Internal slots</a>
    <li><a href="#ref-for-rs-class②⑥">3.9.3. new ReadableStreamDefaultController()</a>
    <li><a href="#ref-for-rs-class②⑦">3.10.4. ReadableStreamDefaultControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-rs-class②⑧">3.11. Class
ReadableByteStreamController</a> <a href="#ref-for-rs-class②⑨">(2)</a>
    <li><a href="#ref-for-rs-class③⓪">3.11.2. Internal slots</a>
    <li><a href="#ref-for-rs-class③①">3.11.3. new
ReadableByteStreamController()</a>
    <li><a href="#ref-for-rs-class③②">3.13.4. ReadableByteStreamControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-rs-class③③">5.2.2. Internal slots</a>
    <li><a href="#ref-for-rs-class③④">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-rs-class③⑤">5.4. Class
TransformStreamDefaultController</a>
    <li><a href="#ref-for-rs-class③⑥">7. Global properties</a>
    <li><a href="#ref-for-rs-class③⑦">8. Examples of creating streams</a>
    <li><a href="#ref-for-rs-class③⑧">8.1. A readable stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-rs-class③⑨">8.3. A readable byte stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-rs-class④⓪">8.5. A readable byte stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-constructor">
   <b><a href="#rs-constructor">#rs-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-constructor">2.1. Readable streams</a>
    <li><a href="#ref-for-rs-constructor">3.2.1. Class definition</a>
    <li><a href="#ref-for-rs-constructor①">3.2.4. Underlying source API</a> <a href="#ref-for-rs-constructor②">(2)</a> <a href="#ref-for-rs-constructor③">(3)</a>
    <li><a href="#ref-for-rs-constructor④">6.1.1. The queuing strategy API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-underlying-source-start">
   <b><a href="#dom-underlying-source-start">#dom-underlying-source-start</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-underlying-source-start">3.2.4. Underlying source API</a> <a href="#ref-for-dom-underlying-source-start①">(2)</a> <a href="#ref-for-dom-underlying-source-start②">(3)</a>
    <li><a href="#ref-for-dom-underlying-source-start③">8.1. A readable stream with an underlying push source (no backpressure support)</a>
    <li><a href="#ref-for-dom-underlying-source-start④">8.4. A readable stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-underlying-source-pull">
   <b><a href="#dom-underlying-source-pull">#dom-underlying-source-pull</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-underlying-source-pull">3.2.4. Underlying source API</a> <a href="#ref-for-dom-underlying-source-pull①">(2)</a> <a href="#ref-for-dom-underlying-source-pull②">(3)</a>
    <li><a href="#ref-for-dom-underlying-source-pull③">3.11.2. Internal slots</a> <a href="#ref-for-dom-underlying-source-pull④">(2)</a>
    <li><a href="#ref-for-dom-underlying-source-pull⑤">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-dom-underlying-source-pull⑥">8.4. A readable stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-underlying-source-cancel">
   <b><a href="#dom-underlying-source-cancel">#dom-underlying-source-cancel</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-underlying-source-cancel">3.2.5.2. cancel(reason)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="underlying-source-type">
   <b><a href="#underlying-source-type">#underlying-source-type</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-underlying-source-type">3.2.4. Underlying source API</a> <a href="#ref-for-underlying-source-type①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="underlying-source-autoallocatechunksize">
   <b><a href="#underlying-source-autoallocatechunksize">#underlying-source-autoallocatechunksize</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-underlying-source-autoallocatechunksize">8.5. A readable byte stream with an underlying pull source</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-locked">
   <b><a href="#rs-locked">#rs-locked</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-locked">2.6. Locking</a>
    <li><a href="#ref-for-rs-locked">3.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-cancel">
   <b><a href="#rs-cancel">#rs-cancel</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-cancel">2.1. Readable streams</a>
    <li><a href="#ref-for-rs-cancel">3.2.1. Class definition</a>
    <li><a href="#ref-for-rs-cancel①">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-rs-cancel②">3.5.4. ReadableStreamClose ( stream )</a>
    <li><a href="#ref-for-rs-cancel③">3.10.10. ReadableStreamDefaultControllerCanCloseOrEnqueue ( controller )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-get-iterator">
   <b><a href="#rs-get-iterator">#rs-get-iterator</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-get-iterator">3.2.1. Class definition</a>
    <li><a href="#ref-for-rs-get-iterator">3.2.5.8. [@@asyncIterator]({ preventCancel } = {})</a> <a href="#ref-for-rs-get-iterator①">(2)</a>
    <li><a href="#ref-for-rs-get-iterator②">3.3. ReadableStreamAsyncIteratorPrototype</a>
    <li><a href="#ref-for-rs-get-iterator③">3.3.1. Internal slots</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-get-reader">
   <b><a href="#rs-get-reader">#rs-get-reader</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-get-reader">2.1. Readable streams</a> <a href="#ref-for-rs-get-reader①">(2)</a>
    <li><a href="#ref-for-rs-get-reader②">2.6. Locking</a>
    <li><a href="#ref-for-rs-get-reader">3.2.1. Class definition</a>
    <li><a href="#ref-for-rs-get-reader③">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-rs-get-reader④">3.6.3. new ReadableStreamDefaultReader(stream)</a>
    <li><a href="#ref-for-rs-get-reader⑤">3.7.3. new
ReadableStreamBYOBReader(stream)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-pipe-through">
   <b><a href="#rs-pipe-through">#rs-pipe-through</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-pipe-through">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-rs-pipe-through">3.2.1. Class definition</a>
    <li><a href="#ref-for-rs-pipe-through①">3.2.5.5. pipeThrough({
writable, readable }, { preventClose, preventAbort,
preventCancel, signal } = {})</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-pipe-to">
   <b><a href="#rs-pipe-to">#rs-pipe-to</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-pipe-to">2.4. Pipe chains and backpressure</a> <a href="#ref-for-rs-pipe-to①">(2)</a>
    <li><a href="#ref-for-rs-pipe-to">3.2.1. Class definition</a>
    <li><a href="#ref-for-rs-pipe-to②">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-rs-pipe-to③">3.5.5. ReadableStreamCreateReadResult
( value, done, forAuthorCode )</a>
    <li><a href="#ref-for-rs-pipe-to④">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-rs-pipe-to⑤">4.6.4. WritableStreamDefaultWriterCloseWithErrorPropagation ( writer )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-tee">
   <b><a href="#rs-tee">#rs-tee</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-tee">2.1. Readable streams</a>
    <li><a href="#ref-for-rs-tee">3.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-asynciterator">
   <b><a href="#rs-asynciterator">#rs-asynciterator</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-asynciterator">3.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-asynciterator-prototype">
   <b><a href="#rs-asynciterator-prototype">#rs-asynciterator-prototype</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-asynciterator-prototype">3.2.5.3. getIterator({ preventCancel } = {})</a>
    <li><a href="#ref-for-rs-asynciterator-prototype①">3.3. ReadableStreamAsyncIteratorPrototype</a> <a href="#ref-for-rs-asynciterator-prototype②">(2)</a> <a href="#ref-for-rs-asynciterator-prototype③">(3)</a>
    <li><a href="#ref-for-rs-asynciterator-prototype④">3.3.1. Internal slots</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-asynciterator-prototype-return">
   <b><a href="#rs-asynciterator-prototype-return">#rs-asynciterator-prototype-return</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-asynciterator-prototype-return">3.2.5.3. getIterator({ preventCancel } = {})</a>
    <li><a href="#ref-for-rs-asynciterator-prototype-return①">3.3.1. Internal slots</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="abstract-opdef-cancelsteps">
   <b><a href="#abstract-opdef-cancelsteps">#abstract-opdef-cancelsteps</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abstract-opdef-cancelsteps">3.5.3. ReadableStreamCancel ( stream,
reason )</a>
    <li><a href="#ref-for-abstract-opdef-cancelsteps①">3.9.5.1. [[CancelSteps]](reason)</a>
    <li><a href="#ref-for-abstract-opdef-cancelsteps②">3.11.5.1. [[CancelSteps]](reason)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="abstract-opdef-pullsteps">
   <b><a href="#abstract-opdef-pullsteps">#abstract-opdef-pullsteps</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-abstract-opdef-pullsteps">3.8.7. ReadableStreamDefaultReaderRead ( reader )</a>
    <li><a href="#ref-for-abstract-opdef-pullsteps①">3.9.5.2. [[PullSteps]]( )</a>
    <li><a href="#ref-for-abstract-opdef-pullsteps②">3.11.5.2. [[PullSteps]]( )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-reader-class">
   <b><a href="#default-reader-class">#default-reader-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-reader-class">2.6. Locking</a>
    <li><a href="#ref-for-default-reader-class①">3.2.2. Internal slots</a>
    <li><a href="#ref-for-default-reader-class②">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-default-reader-class③">3.3.1. Internal slots</a>
    <li><a href="#ref-for-default-reader-class④">3.4.2. AcquireReadableStreamDefaultReader ( stream[, forAuthorCode ] )</a>
    <li><a href="#ref-for-default-reader-class⑤">3.6. Class
ReadableStreamDefaultReader</a>
    <li><a href="#ref-for-default-reader-class⑥">3.6.1. Class definition</a>
    <li><a href="#ref-for-default-reader-class⑦">3.6.2. Internal slots</a>
    <li><a href="#ref-for-default-reader-class⑧">3.6.4. Properties of the ReadableStreamDefaultReader prototype</a>
    <li><a href="#ref-for-default-reader-class⑨">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-reader-constructor">
   <b><a href="#default-reader-constructor">#default-reader-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-reader-constructor">3.6.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-reader-closed">
   <b><a href="#default-reader-closed">#default-reader-closed</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-reader-closed">3.6.1. Class definition</a>
    <li><a href="#ref-for-default-reader-closed">3.6.2. Internal slots</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-reader-cancel">
   <b><a href="#default-reader-cancel">#default-reader-cancel</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-reader-cancel">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-default-reader-cancel">3.6.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-reader-read">
   <b><a href="#default-reader-read">#default-reader-read</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-reader-read">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-default-reader-read①">3.5.5. ReadableStreamCreateReadResult
( value, done, forAuthorCode )</a>
    <li><a href="#ref-for-default-reader-read">3.6.1. Class definition</a>
    <li><a href="#ref-for-default-reader-read②">3.6.2. Internal slots</a>
    <li><a href="#ref-for-default-reader-read③">3.6.4.4. releaseLock()</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-reader-release-lock">
   <b><a href="#default-reader-release-lock">#default-reader-release-lock</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-reader-release-lock">2.6. Locking</a>
    <li><a href="#ref-for-default-reader-release-lock">3.6.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="byob-reader-class">
   <b><a href="#byob-reader-class">#byob-reader-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-byob-reader-class">2.6. Locking</a>
    <li><a href="#ref-for-byob-reader-class①">3.2.2. Internal slots</a>
    <li><a href="#ref-for-byob-reader-class②">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-byob-reader-class③">3.4.1. AcquireReadableStreamBYOBReader ( stream[, forAuthorCode ] )</a>
    <li><a href="#ref-for-byob-reader-class④">3.7. Class ReadableStreamBYOBReader</a>
    <li><a href="#ref-for-byob-reader-class⑤">3.7.1. Class definition</a>
    <li><a href="#ref-for-byob-reader-class⑥">3.7.2. Internal slots</a>
    <li><a href="#ref-for-byob-reader-class⑦">3.7.4. Properties of the ReadableStreamBYOBReader prototype</a>
    <li><a href="#ref-for-byob-reader-class⑧">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="byob-reader-constructor">
   <b><a href="#byob-reader-constructor">#byob-reader-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-byob-reader-constructor">3.7.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="byob-reader-closed">
   <b><a href="#byob-reader-closed">#byob-reader-closed</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-byob-reader-closed">3.7.1. Class definition</a>
    <li><a href="#ref-for-byob-reader-closed">3.7.2. Internal slots</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="byob-reader-cancel">
   <b><a href="#byob-reader-cancel">#byob-reader-cancel</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-byob-reader-cancel">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-byob-reader-cancel">3.7.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="byob-reader-read">
   <b><a href="#byob-reader-read">#byob-reader-read</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-byob-reader-read">3.2.5.4. getReader({ mode } = {})</a>
    <li><a href="#ref-for-byob-reader-read①">3.5.5. ReadableStreamCreateReadResult
( value, done, forAuthorCode )</a>
    <li><a href="#ref-for-byob-reader-read">3.7.1. Class definition</a>
    <li><a href="#ref-for-byob-reader-read②">3.7.2. Internal slots</a>
    <li><a href="#ref-for-byob-reader-read③">3.7.4.4. releaseLock()</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="byob-reader-release-lock">
   <b><a href="#byob-reader-release-lock">#byob-reader-release-lock</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-byob-reader-release-lock">2.6. Locking</a>
    <li><a href="#ref-for-byob-reader-release-lock">3.7.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-default-controller-class">
   <b><a href="#rs-default-controller-class">#rs-default-controller-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-default-controller-class">3.2.2. Internal slots</a>
    <li><a href="#ref-for-rs-default-controller-class①">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-rs-default-controller-class②">3.4.3. CreateReadableStream (
startAlgorithm, pullAlgorithm, cancelAlgorithm [, highWaterMark [,
sizeAlgorithm ] ] )</a>
    <li><a href="#ref-for-rs-default-controller-class③">3.5. The interface between readable streams and controllers</a>
    <li><a href="#ref-for-rs-default-controller-class④">3.9. Class
ReadableStreamDefaultController</a> <a href="#ref-for-rs-default-controller-class⑤">(2)</a>
    <li><a href="#ref-for-rs-default-controller-class⑥">3.9.1. Class definition</a>
    <li><a href="#ref-for-rs-default-controller-class⑦">3.9.2. Internal slots</a>
    <li><a href="#ref-for-rs-default-controller-class⑧">3.9.3. new ReadableStreamDefaultController()</a>
    <li><a href="#ref-for-rs-default-controller-class⑨">3.9.4. Properties of the ReadableStreamDefaultController prototype</a>
    <li><a href="#ref-for-rs-default-controller-class①⓪">3.9.5. Readable stream default controller internal methods</a>
    <li><a href="#ref-for-rs-default-controller-class①①">3.10.12. SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource,
highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-rs-default-controller-class①②">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-default-controller-constructor">
   <b><a href="#rs-default-controller-constructor">#rs-default-controller-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-default-controller-constructor">3.9.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-default-controller-desired-size">
   <b><a href="#rs-default-controller-desired-size">#rs-default-controller-desired-size</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-default-controller-desired-size">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-rs-default-controller-desired-size">3.9.1. Class definition</a>
    <li><a href="#ref-for-rs-default-controller-desired-size①">3.10.8. ReadableStreamDefaultControllerGetDesiredSize ( controller )</a>
    <li><a href="#ref-for-rs-default-controller-desired-size②">6.1.1. The queuing strategy API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-default-controller-close">
   <b><a href="#rs-default-controller-close">#rs-default-controller-close</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-default-controller-close">3.9.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-default-controller-enqueue">
   <b><a href="#rs-default-controller-enqueue">#rs-default-controller-enqueue</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-default-controller-enqueue">3.9.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-default-controller-error">
   <b><a href="#rs-default-controller-error">#rs-default-controller-error</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-default-controller-error">3.9.1. Class definition</a>
    <li><a href="#ref-for-rs-default-controller-error">3.10.10. ReadableStreamDefaultControllerCanCloseOrEnqueue ( controller )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rbs-controller-class">
   <b><a href="#rbs-controller-class">#rbs-controller-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rbs-controller-class">3.2.2. Internal slots</a>
    <li><a href="#ref-for-rbs-controller-class①">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-rbs-controller-class②">3.4.4. CreateReadableByteStream (
startAlgorithm, pullAlgorithm, cancelAlgorithm [, highWaterMark [,
autoAllocateChunkSize ] ] )</a>
    <li><a href="#ref-for-rbs-controller-class③">3.5. The interface between readable streams and controllers</a>
    <li><a href="#ref-for-rbs-controller-class④">3.11. Class
ReadableByteStreamController</a> <a href="#ref-for-rbs-controller-class⑤">(2)</a>
    <li><a href="#ref-for-rbs-controller-class⑥">3.11.1. Class definition</a>
    <li><a href="#ref-for-rbs-controller-class⑦">3.11.2. Internal slots</a> <a href="#ref-for-rbs-controller-class⑧">(2)</a>
    <li><a href="#ref-for-rbs-controller-class⑨">3.11.3. new
ReadableByteStreamController()</a>
    <li><a href="#ref-for-rbs-controller-class①⓪">3.11.4. Properties of the ReadableByteStreamController prototype</a>
    <li><a href="#ref-for-rbs-controller-class①①">3.11.5. Readable stream BYOB controller internal methods</a>
    <li><a href="#ref-for-rbs-controller-class①②">3.12. Class
ReadableStreamBYOBRequest</a>
    <li><a href="#ref-for-rbs-controller-class①③">3.12.2. Internal slots</a>
    <li><a href="#ref-for-rbs-controller-class①④">3.13.27. SetUpReadableByteStreamControllerFromUnderlyingSource ( stream,
underlyingByteSource, highWaterMark )</a>
    <li><a href="#ref-for-rbs-controller-class①⑤">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rbs-controller-constructor">
   <b><a href="#rbs-controller-constructor">#rbs-controller-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rbs-controller-constructor">3.11.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rbs-controller-byob-request">
   <b><a href="#rbs-controller-byob-request">#rbs-controller-byob-request</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rbs-controller-byob-request">3.2.4. Underlying source API</a>
    <li><a href="#ref-for-rbs-controller-byob-request">3.11.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rbs-controller-desired-size">
   <b><a href="#rbs-controller-desired-size">#rbs-controller-desired-size</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rbs-controller-desired-size">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-rbs-controller-desired-size">3.11.1. Class definition</a>
    <li><a href="#ref-for-rbs-controller-desired-size①">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-rbs-controller-desired-size②">8.3. A readable byte stream with an underlying push source (no backpressure support)</a> <a href="#ref-for-rbs-controller-desired-size③">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rbs-controller-close">
   <b><a href="#rbs-controller-close">#rbs-controller-close</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rbs-controller-close">3.11.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rbs-controller-enqueue">
   <b><a href="#rbs-controller-enqueue">#rbs-controller-enqueue</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rbs-controller-enqueue">3.11.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rbs-controller-error">
   <b><a href="#rbs-controller-error">#rbs-controller-error</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rbs-controller-error">3.11.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-byob-request-class">
   <b><a href="#rs-byob-request-class">#rs-byob-request-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-byob-request-class">3.11.2. Internal slots</a>
    <li><a href="#ref-for-rs-byob-request-class①">3.11.4.1. get byobRequest</a>
    <li><a href="#ref-for-rs-byob-request-class②">3.12. Class
ReadableStreamBYOBRequest</a>
    <li><a href="#ref-for-rs-byob-request-class③">3.12.1. Class definition</a>
    <li><a href="#ref-for-rs-byob-request-class④">3.12.2. Internal slots</a>
    <li><a href="#ref-for-rs-byob-request-class⑤">3.12.4. Properties of the ReadableStreamBYOBRequest prototype</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-byob-request-constructor">
   <b><a href="#rs-byob-request-constructor">#rs-byob-request-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-byob-request-constructor">3.12.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-byob-request-view">
   <b><a href="#rs-byob-request-view">#rs-byob-request-view</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-byob-request-view">3.12.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-byob-request-respond">
   <b><a href="#rs-byob-request-respond">#rs-byob-request-respond</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-byob-request-respond">3.12.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="rs-byob-request-respond-with-new-view">
   <b><a href="#rs-byob-request-respond-with-new-view">#rs-byob-request-respond-with-new-view</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-rs-byob-request-respond-with-new-view">3.12.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-class">
   <b><a href="#ws-class">#ws-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-class">2.2. Writable streams</a>
    <li><a href="#ref-for-ws-class①">4.2.1. Class definition</a>
    <li><a href="#ref-for-ws-class②">4.2.2. Internal slots</a>
    <li><a href="#ref-for-ws-class③">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-ws-class④">4.2.5. Properties of the WritableStream prototype</a>
    <li><a href="#ref-for-ws-class⑤">4.3.2. CreateWritableStream ( startAlgorithm,
writeAlgorithm, closeAlgorithm, abortAlgorithm [, highWaterMark [,
sizeAlgorithm ] ] )</a> <a href="#ref-for-ws-class⑥">(2)</a>
    <li><a href="#ref-for-ws-class⑦">4.4. Writable stream abstract operations used by controllers</a> <a href="#ref-for-ws-class⑧">(2)</a>
    <li><a href="#ref-for-ws-class⑨">4.5. Class
WritableStreamDefaultWriter</a>
    <li><a href="#ref-for-ws-class①⓪">4.5.2. Internal slots</a>
    <li><a href="#ref-for-ws-class①①">4.7. Class
WritableStreamDefaultController</a> <a href="#ref-for-ws-class①②">(2)</a>
    <li><a href="#ref-for-ws-class①③">4.7.2. Internal slots</a>
    <li><a href="#ref-for-ws-class①④">4.7.3. new WritableStreamDefaultController()</a>
    <li><a href="#ref-for-ws-class①⑤">4.8.4. WritableStreamDefaultControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-ws-class①⑥">5.2.2. Internal slots</a>
    <li><a href="#ref-for-ws-class①⑦">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-ws-class①⑧">5.4. Class
TransformStreamDefaultController</a>
    <li><a href="#ref-for-ws-class①⑨">7. Global properties</a>
    <li><a href="#ref-for-ws-class②⓪">8. Examples of creating streams</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-constructor">
   <b><a href="#ws-constructor">#ws-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-constructor">2.2. Writable streams</a>
    <li><a href="#ref-for-ws-constructor">4.2.1. Class definition</a>
    <li><a href="#ref-for-ws-constructor①">4.2.4. Underlying sink API</a> <a href="#ref-for-ws-constructor②">(2)</a>
    <li><a href="#ref-for-ws-constructor③">6.1.1. The queuing strategy API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-underlying-sink-start">
   <b><a href="#dom-underlying-sink-start">#dom-underlying-sink-start</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-underlying-sink-start">4.2.4. Underlying sink API</a> <a href="#ref-for-dom-underlying-sink-start①">(2)</a>
    <li><a href="#ref-for-dom-underlying-sink-start②">5.2.4. Transformer API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-underlying-sink-write">
   <b><a href="#dom-underlying-sink-write">#dom-underlying-sink-write</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-underlying-sink-write">3.1. Using readable streams</a>
    <li><a href="#ref-for-dom-underlying-sink-write①">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-dom-underlying-sink-write②">4.5.4.7. write(chunk)</a>
    <li><a href="#ref-for-dom-underlying-sink-write③">8.7. A writable stream with backpressure and success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-underlying-sink-close">
   <b><a href="#dom-underlying-sink-close">#dom-underlying-sink-close</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-underlying-sink-close">4.2.4. Underlying sink API</a> <a href="#ref-for-dom-underlying-sink-close①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-underlying-sink-abort">
   <b><a href="#dom-underlying-sink-abort">#dom-underlying-sink-abort</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-underlying-sink-abort">4.2.4. Underlying sink API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-locked">
   <b><a href="#ws-locked">#ws-locked</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-locked">2.6. Locking</a>
    <li><a href="#ref-for-ws-locked">4.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-abort">
   <b><a href="#ws-abort">#ws-abort</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-abort">2.2. Writable streams</a>
    <li><a href="#ref-for-ws-abort">4.2.1. Class definition</a>
    <li><a href="#ref-for-ws-abort①">4.2.4. Underlying sink API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-close">
   <b><a href="#ws-close">#ws-close</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-close">4.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-get-writer">
   <b><a href="#ws-get-writer">#ws-get-writer</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-get-writer">4.2.1. Class definition</a>
    <li><a href="#ref-for-ws-get-writer">4.5.3. new WritableStreamDefaultWriter(stream)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-class">
   <b><a href="#default-writer-class">#default-writer-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-class">2.6. Locking</a>
    <li><a href="#ref-for-default-writer-class①">4.1. Using writable streams</a>
    <li><a href="#ref-for-default-writer-class②">4.2.2. Internal slots</a>
    <li><a href="#ref-for-default-writer-class③">4.2.5.4. getWriter()</a>
    <li><a href="#ref-for-default-writer-class④">4.3.1. AcquireWritableStreamDefaultWriter ( stream )</a>
    <li><a href="#ref-for-default-writer-class⑤">4.5. Class
WritableStreamDefaultWriter</a>
    <li><a href="#ref-for-default-writer-class⑥">4.5.1. Class definition</a>
    <li><a href="#ref-for-default-writer-class⑦">4.5.2. Internal slots</a>
    <li><a href="#ref-for-default-writer-class⑧">4.5.4. Properties of the WritableStreamDefaultWriter prototype</a>
    <li><a href="#ref-for-default-writer-class⑨">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-constructor">
   <b><a href="#default-writer-constructor">#default-writer-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-constructor">4.5.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-closed">
   <b><a href="#default-writer-closed">#default-writer-closed</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-closed">4.5.1. Class definition</a>
    <li><a href="#ref-for-default-writer-closed">4.5.2. Internal slots</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-desired-size">
   <b><a href="#default-writer-desired-size">#default-writer-desired-size</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-desired-size">2.4. Pipe chains and backpressure</a>
    <li><a href="#ref-for-default-writer-desired-size①">4.1. Using writable streams</a> <a href="#ref-for-default-writer-desired-size②">(2)</a> <a href="#ref-for-default-writer-desired-size③">(3)</a>
    <li><a href="#ref-for-default-writer-desired-size④">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-default-writer-desired-size">4.5.1. Class definition</a>
    <li><a href="#ref-for-default-writer-desired-size⑤">6.1.1. The queuing strategy API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-ready">
   <b><a href="#default-writer-ready">#default-writer-ready</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-ready">4.1. Using writable streams</a> <a href="#ref-for-default-writer-ready①">(2)</a> <a href="#ref-for-default-writer-ready②">(3)</a> <a href="#ref-for-default-writer-ready③">(4)</a> <a href="#ref-for-default-writer-ready④">(5)</a> <a href="#ref-for-default-writer-ready⑤">(6)</a> <a href="#ref-for-default-writer-ready⑥">(7)</a>
    <li><a href="#ref-for-default-writer-ready">4.5.1. Class definition</a>
    <li><a href="#ref-for-default-writer-ready⑦">4.5.2. Internal slots</a>
    <li><a href="#ref-for-default-writer-ready⑧">8.6. A writable stream with no backpressure or success signals</a>
    <li><a href="#ref-for-default-writer-ready⑨">8.7. A writable stream with backpressure and success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-abort">
   <b><a href="#default-writer-abort">#default-writer-abort</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-abort">4.2.2. Internal slots</a> <a href="#ref-for-default-writer-abort①">(2)</a> <a href="#ref-for-default-writer-abort②">(3)</a>
    <li><a href="#ref-for-default-writer-abort③">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-default-writer-abort">4.5.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-close">
   <b><a href="#default-writer-close">#default-writer-close</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-close">4.1. Using writable streams</a> <a href="#ref-for-default-writer-close①">(2)</a> <a href="#ref-for-default-writer-close②">(3)</a>
    <li><a href="#ref-for-default-writer-close③">4.2.2. Internal slots</a>
    <li><a href="#ref-for-default-writer-close④">4.2.4. Underlying sink API</a> <a href="#ref-for-default-writer-close⑤">(2)</a>
    <li><a href="#ref-for-default-writer-close">4.5.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-release-lock">
   <b><a href="#default-writer-release-lock">#default-writer-release-lock</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-release-lock">2.6. Locking</a>
    <li><a href="#ref-for-default-writer-release-lock">4.5.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="default-writer-write">
   <b><a href="#default-writer-write">#default-writer-write</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-default-writer-write">4.1. Using writable streams</a> <a href="#ref-for-default-writer-write①">(2)</a> <a href="#ref-for-default-writer-write②">(3)</a> <a href="#ref-for-default-writer-write③">(4)</a> <a href="#ref-for-default-writer-write④">(5)</a> <a href="#ref-for-default-writer-write⑤">(6)</a> <a href="#ref-for-default-writer-write⑥">(7)</a> <a href="#ref-for-default-writer-write⑦">(8)</a> <a href="#ref-for-default-writer-write⑧">(9)</a>
    <li><a href="#ref-for-default-writer-write⑨">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-default-writer-write">4.5.1. Class definition</a>
    <li><a href="#ref-for-default-writer-write①⓪">4.5.4.6. releaseLock()</a>
    <li><a href="#ref-for-default-writer-write①①">5.2.4. Transformer API</a>
    <li><a href="#ref-for-default-writer-write①②">8.6. A writable stream with no backpressure or success signals</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-default-controller-class">
   <b><a href="#ws-default-controller-class">#ws-default-controller-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-default-controller-class">4.2.2. Internal slots</a>
    <li><a href="#ref-for-ws-default-controller-class①">4.2.4. Underlying sink API</a>
    <li><a href="#ref-for-ws-default-controller-class②">4.3.2. CreateWritableStream ( startAlgorithm,
writeAlgorithm, closeAlgorithm, abortAlgorithm [, highWaterMark [,
sizeAlgorithm ] ] )</a>
    <li><a href="#ref-for-ws-default-controller-class③">4.4. Writable stream abstract operations used by controllers</a>
    <li><a href="#ref-for-ws-default-controller-class④">4.7. Class
WritableStreamDefaultController</a> <a href="#ref-for-ws-default-controller-class⑤">(2)</a>
    <li><a href="#ref-for-ws-default-controller-class⑥">4.7.1. Class definition</a>
    <li><a href="#ref-for-ws-default-controller-class⑦">4.7.2. Internal slots</a>
    <li><a href="#ref-for-ws-default-controller-class⑧">4.7.3. new WritableStreamDefaultController()</a>
    <li><a href="#ref-for-ws-default-controller-class⑨">4.7.4. Properties of the WritableStreamDefaultController prototype</a>
    <li><a href="#ref-for-ws-default-controller-class①⓪">4.7.5. Writable stream default controller internal methods</a>
    <li><a href="#ref-for-ws-default-controller-class①①">4.8.3. SetUpWritableStreamDefaultControllerFromUnderlyingSink ( stream, underlyingSink,
highWaterMark, sizeAlgorithm )</a>
    <li><a href="#ref-for-ws-default-controller-class①②">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-default-controller-constructor">
   <b><a href="#ws-default-controller-constructor">#ws-default-controller-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-default-controller-constructor">4.7.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ws-default-controller-error">
   <b><a href="#ws-default-controller-error">#ws-default-controller-error</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ws-default-controller-error">4.7.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-class">
   <b><a href="#ts-class">#ts-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-class">2.3. Transform streams</a> <a href="#ref-for-ts-class①">(2)</a>
    <li><a href="#ref-for-ts-class②">5.2.1. Class definition</a>
    <li><a href="#ref-for-ts-class③">5.2.2. Internal slots</a>
    <li><a href="#ref-for-ts-class④">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-ts-class⑤">5.2.4. Transformer API</a>
    <li><a href="#ref-for-ts-class⑥">5.2.5. Properties of the TransformStream prototype</a>
    <li><a href="#ref-for-ts-class⑦">5.3.1. CreateTransformStream (
startAlgorithm, transformAlgorithm, flushAlgorithm
[, writableHighWaterMark [, writableSizeAlgorithm [, readableHighWaterMark [,
readableSizeAlgorithm ] ] ] ] )</a> <a href="#ref-for-ts-class⑧">(2)</a>
    <li><a href="#ref-for-ts-class⑨">5.4. Class
TransformStreamDefaultController</a>
    <li><a href="#ref-for-ts-class①⓪">5.4.2. Internal slots</a>
    <li><a href="#ref-for-ts-class①①">5.4.3. new TransformStreamDefaultController()</a>
    <li><a href="#ref-for-ts-class①②">5.5.4. TransformStreamDefaultControllerClearAlgorithms ( controller )</a>
    <li><a href="#ref-for-ts-class①③">7. Global properties</a>
    <li><a href="#ref-for-ts-class①④">8.9. A transform stream that replaces template tags</a>
    <li><a href="#ref-for-ts-class①⑤">8.10. A transform stream created from a sync mapper function</a> <a href="#ref-for-ts-class①⑥">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-constructor">
   <b><a href="#ts-constructor">#ts-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-constructor">2.3. Transform streams</a>
    <li><a href="#ref-for-ts-constructor">5.2.1. Class definition</a>
    <li><a href="#ref-for-ts-constructor①">5.2.4. Transformer API</a> <a href="#ref-for-ts-constructor②">(2)</a>
    <li><a href="#ref-for-ts-constructor③">6.1.1. The queuing strategy API</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-transformer-start">
   <b><a href="#dom-transformer-start">#dom-transformer-start</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-transformer-start">5.2.4. Transformer API</a>
    <li><a href="#ref-for-dom-transformer-start①">5.3.2. InitializeTransformStream (
stream, startPromise, writableHighWaterMark, writableSizeAlgorithm,
readableHighWaterMark, readableSizeAlgorithm )</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-transformer-transform">
   <b><a href="#dom-transformer-transform">#dom-transformer-transform</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-transformer-transform">2.3. Transform streams</a>
    <li><a href="#ref-for-dom-transformer-transform①">5.2.4. Transformer API</a> <a href="#ref-for-dom-transformer-transform②">(2)</a> <a href="#ref-for-dom-transformer-transform③">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-transformer-flush">
   <b><a href="#dom-transformer-flush">#dom-transformer-flush</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-transformer-flush">5.2.4. Transformer API</a> <a href="#ref-for-dom-transformer-flush①">(2)</a> <a href="#ref-for-dom-transformer-flush②">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-readable">
   <b><a href="#ts-readable">#ts-readable</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-readable">5.1. Using transform streams</a>
    <li><a href="#ref-for-ts-readable">5.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-writable">
   <b><a href="#ts-writable">#ts-writable</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-writable">5.1. Using transform streams</a>
    <li><a href="#ref-for-ts-writable">5.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-default-controller-class">
   <b><a href="#ts-default-controller-class">#ts-default-controller-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-default-controller-class">5.2.2. Internal slots</a>
    <li><a href="#ref-for-ts-default-controller-class①">5.2.4. Transformer API</a>
    <li><a href="#ref-for-ts-default-controller-class②">5.3.1. CreateTransformStream (
startAlgorithm, transformAlgorithm, flushAlgorithm
[, writableHighWaterMark [, writableSizeAlgorithm [, readableHighWaterMark [,
readableSizeAlgorithm ] ] ] ] )</a>
    <li><a href="#ref-for-ts-default-controller-class③">5.4. Class
TransformStreamDefaultController</a> <a href="#ref-for-ts-default-controller-class④">(2)</a>
    <li><a href="#ref-for-ts-default-controller-class⑤">5.4.1. Class definition</a>
    <li><a href="#ref-for-ts-default-controller-class⑥">5.4.2. Internal slots</a>
    <li><a href="#ref-for-ts-default-controller-class⑦">5.4.3. new TransformStreamDefaultController()</a>
    <li><a href="#ref-for-ts-default-controller-class⑧">5.4.4. Properties of the TransformStreamDefaultController prototype</a>
    <li><a href="#ref-for-ts-default-controller-class⑨">5.5.3. SetUpTransformStreamDefaultControllerFromTransformer ( stream, transformer )</a>
    <li><a href="#ref-for-ts-default-controller-class①⓪">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-default-controller-constructor">
   <b><a href="#ts-default-controller-constructor">#ts-default-controller-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-default-controller-constructor">5.4.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-default-controller-desired-size">
   <b><a href="#ts-default-controller-desired-size">#ts-default-controller-desired-size</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-default-controller-desired-size">5.4.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-default-controller-enqueue">
   <b><a href="#ts-default-controller-enqueue">#ts-default-controller-enqueue</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-default-controller-enqueue">5.2.4. Transformer API</a> <a href="#ref-for-ts-default-controller-enqueue①">(2)</a> <a href="#ref-for-ts-default-controller-enqueue②">(3)</a>
    <li><a href="#ref-for-ts-default-controller-enqueue">5.4.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-default-controller-error">
   <b><a href="#ts-default-controller-error">#ts-default-controller-error</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-default-controller-error">5.4.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="ts-default-controller-terminate">
   <b><a href="#ts-default-controller-terminate">#ts-default-controller-terminate</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-ts-default-controller-terminate">5.2.4. Transformer API</a>
    <li><a href="#ref-for-ts-default-controller-terminate">5.4.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="dom-queuing-strategy-size">
   <b><a href="#dom-queuing-strategy-size">#dom-queuing-strategy-size</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-dom-queuing-strategy-size">2.5. Internal queues and queuing strategies</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="queuing-strategy-highwatermark">
   <b><a href="#queuing-strategy-highwatermark">#queuing-strategy-highwatermark</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-queuing-strategy-highwatermark">2.5. Internal queues and queuing strategies</a> <a href="#ref-for-queuing-strategy-highwatermark①">(2)</a> <a href="#ref-for-queuing-strategy-highwatermark②">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="blqs-class">
   <b><a href="#blqs-class">#blqs-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-blqs-class">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-blqs-class①">6.1.2. Class ByteLengthQueuingStrategy</a> <a href="#ref-for-blqs-class②">(2)</a>
    <li><a href="#ref-for-blqs-class③">6.1.2.1. Class definition</a> <a href="#ref-for-blqs-class④">(2)</a>
    <li><a href="#ref-for-blqs-class⑤">6.1.2.3. Properties of the ByteLengthQueuingStrategy prototype</a>
    <li><a href="#ref-for-blqs-class⑥">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="blqs-constructor">
   <b><a href="#blqs-constructor">#blqs-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-blqs-constructor">6.1.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="blqs-size">
   <b><a href="#blqs-size">#blqs-size</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-blqs-size">6.1.2.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="cqs-class">
   <b><a href="#cqs-class">#cqs-class</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-cqs-class">2.5. Internal queues and queuing strategies</a>
    <li><a href="#ref-for-cqs-class①">3.2.3. new
ReadableStream(underlyingSource = {}, strategy = {})</a>
    <li><a href="#ref-for-cqs-class②">4.2.3. new
WritableStream(underlyingSink = {}, strategy = {})</a>
    <li><a href="#ref-for-cqs-class③">5.2.3. new TransformStream(transformer = {}, writableStrategy = {},
readableStrategy = {})</a>
    <li><a href="#ref-for-cqs-class④">6.1.1. The queuing strategy API</a>
    <li><a href="#ref-for-cqs-class⑤">6.1.3.1. Class definition</a> <a href="#ref-for-cqs-class⑥">(2)</a>
    <li><a href="#ref-for-cqs-class⑦">6.1.3.3. Properties of the CountQueuingStrategy prototype</a>
    <li><a href="#ref-for-cqs-class⑧">7. Global properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="cqs-constructor">
   <b><a href="#cqs-constructor">#cqs-constructor</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-cqs-constructor">6.1.3.1. Class definition</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="cqs-size">
   <b><a href="#cqs-size">#cqs-size</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-cqs-size">6.1.3.1. Class definition</a>
   </ul>
  </aside>
<script>/* script-dfn-panel */

document.body.addEventListener("click", function(e) {
    var queryAll = function(sel) { return [].slice.call(document.querySelectorAll(sel)); }
    // Find the dfn element or panel, if any, that was clicked on.
    var el = e.target;
    var target;
    var hitALink = false;
    while(el.parentElement) {
        if(el.tagName == "A") {
            // Clicking on a link in a <dfn> shouldn't summon the panel
            hitALink = true;
        }
        if(el.classList.contains("dfn-paneled")) {
            target = "dfn";
            break;
        }
        if(el.classList.contains("dfn-panel")) {
            target = "dfn-panel";
            break;
        }
        el = el.parentElement;
    }
    if(target != "dfn-panel") {
        // Turn off any currently "on" or "activated" panels.
        queryAll(".dfn-panel.on, .dfn-panel.activated").forEach(function(el){
            el.classList.remove("on");
            el.classList.remove("activated");
        });
    }
    if(target == "dfn" && !hitALink) {
        // open the panel
        var dfnPanel = document.querySelector(".dfn-panel[data-for='" + el.id + "']");
        if(dfnPanel) {
            dfnPanel.classList.add("on");
            var rect = el.getBoundingClientRect();
            dfnPanel.style.left = window.scrollX + rect.right + 5 + "px";
            dfnPanel.style.top = window.scrollY + rect.top + "px";
            var panelRect = dfnPanel.getBoundingClientRect();
            var panelWidth = panelRect.right - panelRect.left;
            if(panelRect.right > document.body.scrollWidth && (rect.left - (panelWidth + 5)) > 0) {
                // Reposition, because the panel is overflowing
                dfnPanel.style.left = window.scrollX + rect.left - (panelWidth + 5) + "px";
            }
        } else {
            console.log("Couldn't find .dfn-panel[data-for='" + el.id + "']");
        }
    } else if(target == "dfn-panel") {
        // Switch it to "activated" state, which pins it.
        el.classList.add("activated");
        el.style.left = null;
        el.style.top = null;
    }

});
</script>